0% found this document useful (0 votes)
28 views11 pages

PPS 2

The document discusses 10 programming problems related to Python. The problems cover topics like string manipulation, list processing, conditional logic, dictionaries and more. Complete solutions are not provided, rather the problems are described to be solved as programming exercises.

Uploaded by

ranjithran0505
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views11 pages

PPS 2

The document discusses 10 programming problems related to Python. The problems cover topics like string manipulation, list processing, conditional logic, dictionaries and more. Complete solutions are not provided, rather the problems are described to be solved as programming exercises.

Uploaded by

ranjithran0505
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

NAME : K.

RANJITH
REG NO : 23BCT0208
SUBJECT : COMPUTER
PROGRAMING
SUBJECT CODE : BCSE101E
ASSIGNMENT NO : PPS -2
FACULTY : Prof .TAMILSEVI
1 . Write a function PrintArmstrong() to print Armstrong numbers till a given
number N. Also write another function isArmstrong() to check whether a given
number is Armstrong or not. (Function)
Armstrong number is a number that is equal to the sum of cubes of its digits. For
example 0, 1, 153, 370, 371 and 407 are the Armstrong numbers
For example:

Input Result

371 Yes, Armstrong number till 371 are: 0, 1, 153, 370

1000 No, Armstrong number till 1000 are: 0, 1, 153, 370, 371,
407
2. Develop a Python program to check whether a given string follows the floating-
point number format or not.

 There may be no digits before the point (such as .425) or maybe digits (such as
0.425 or 285.90), all these cases will be considered as valid.

 The input can have an optional sign (+/-) (such as +.25, -0.86, or -.12 ) will be
considered as valid.

 If the string has no characters after the decimal point, it will be considered an
invalid case (such as 12.).

 You should print either valid or invalid (all in lowercase without quotes).

Input Format:-
Read the string in line
Output Format:-
valid (if format satisfies)
invalid (if format not satisfied)
Sample inputs and outputs
+4.50 valid
-1.0 valid
.5 valid
-.7 valid
3. Develop a security system that works with the Caeser cipher. Caesar cipher
rotates each letter of the plaintext forward three times to encrypt, so that A
becomes D, B becomes E, etc. Let the given string be ”python” and the key be 3
letters away from each letter of the alphabet. So” python” becomes ”sbwkrq”.
Consider the input be case sensitive.
Sample Input and Output
Input: ComPuTer
Output: FrpSxWhu
4. A course instructor wants to compute the overall GPA of a student based on
his performance throughout the semester. The maximum GPA is 10. Write a
Python program to perform the following task:
a) Get the mark from the instructor and store it in a dictionary, student.
b) Check the validity of the mark based on the policy given in the table
c) If the marks for any component are either negative (<0) or greater than the
corresponding Maximum Marks, then print the error message as “ERROR: Invalid
Marks <reason>”. Otherwise, print “All marks are valid”.
d) Evaluate a student’s GPA based on the above policy and assign the grade.
e) Update the dictionary 'Student' with GPA and Grade (as key value pair) and print
the dictionary.
5. The cumulative sum of the list [a,b,c] is defined as [a, a+b, a+b+c]. Write a
Python program to input a list of numbers and then create another list from this
list that contains the cumulative sum.
Input Format: -
Read the input list
Output Format: -
Print the other list, which is the cumulative sum of the previous list.
6. Write a Python program that creates a list of friends based on the count and
the names entered by the user. Do the following tasks on the created list:
1) The program should print the created list.
2) Modify the list from step 1 by inserting one of your new friends at your
preferred position and print the modified list.
3) Print the list obtained in step 2 in reverse order.
4) Print the names of the friends in alphabetical order as a list
5) Finally, print the friends' names in step 2 with their index.
7. Suppose you have a string S, which has length N and is indexed from 0 to N-1.
Let string R be the reverse of the string S. The string S is funny if the condition |S[i]
− S[i−1]|= |R[i] − R[i−1]| is true for every i from 1 to N-1. Write a program to
check if a given string is funny.
Note: Consider the ASCII value of the characters when performing the operations.
Sample input and Output
input: acxz
output: funny
input: abctr
output: not funny
8. Assume there are N students in a class, and you have access to the student
information database. You have discovered that X students play hockey, Y students
play basketball, Z students play cricket, and B students play both hockey and
basketball, C students play cricket and basketball, D students play hockey and
cricket, and E students do not play any of the three games. Create a Python
program to find:
A) How many plays hockey, basketball and cricket.
B) How many plays hockey but not cricket.
C) How many plays hockey or cricket but not basketball.
Input Format:
Each input for N, X, Y, Z, B, C, D, E in newline
Output Format:
Output for question A, B and C in newline
9. Write a Python program to round the numbers in a given list, print the
minimum and maximum numbers and multiply the numbers by 5. Print the unique
numbers in ascending order separated by space.
Test Input Output
Ca9.ses
1. [22.4, 4.0, 16.22, 9.1, 11.0, 12.22, 14.2, 5.2, Minimum value: 4
17.5] Maximum value: 22
20 25 45 55 60 70 80 90
110

2. [5.0, 28.67, 5.0, 35.67, 0.8, 9.12, 234.9, 1.78] Minimum value: 1
Maximum value: 235
5 10 25 45 145 180 1175
3. [-1.9, 18.92, 0.2, -45.78, 125.90, -67.90, 9.67] Minimum value: -68
Maximum value: 126
-340 -230 -10 0 50 95 630
10. Write a Python program that accepts two statements (statement1 &
statement2) from the user as input. The program should perform the following
tasks:
1. For the given statement1, capitalize the first character of each word and print
the modified statement.
2. Ask the user to input a substring. Capitalize each letter of the entered substring
in both statement1 & statement2. Print the modified statements. If the substring is
not found in the statement, the program should not print anything.
3. Ask the user to input a word. Merge statement1 & statement2 and print the
count of the entered word in the merged statement. If the word is not present in
the merged statement it should print: Word not found.

You might also like