Practice Programs
Practice Programs
1. Python Program to take three numbers from the user and print the
greatest number.
3. Write a program to print any person is eligible for vote or not (age
Ex: if Input: N = 4
Then Output: 30
12 + 22 + 32 + 42 = 1 + 4 + 9 + 16 = 30
Input
5
Output
*
**
***
****
*****
****
***
**
*
UNIT-3
Programs of String:
5. Write a program to find the first and the last occurrence of the letter
in a String.
6. Write a program that takes your full name as input and displays the
abbreviations of the first and middle names except the last name
which is displayed as it is. For example, if your name is Robert Brett
Roser, then the output should be R.B.Roser.
8. Write a program to make a new string with all the consonants deleted
from a string.
9. Write a Python program to get a single string from two given strings,
separated by a space and swap the first two characters of each string.
Sample Input: abc xyz
Sample Output: xyc abz
10. Write a Python program to get a string from a given string where all
occurrences of its first char have been changed to '$', except the first
char itself.
Sample Input: restart
Sample Output: resta$t
11. Write a Python program to add 'ing' at the end of a given string
(length should be at least 3). If the given string already ends with 'ing'
then add 'ly' instead. If the string length of the given string is less than
3, leave it unchanged.
Sample String : 'abc'
Expected Result : 'abcing'
Sample String : 'string'
Expected Result : 'stringly'
13. Write a Python program to remove the nth index character from a
nonempty string.
14. Write a Python program to remove the characters which have odd
index values of a given string.
3. Write a program to get the largest and smallest number from a list.
10. Write a Python program to get the 4th element from the last
element of a tuple.
tuples.
Original lists:
(1, 2, 3, 4)
(3, 5, 2, 1)
(2, 2, 3, 1)
Element-wise sum of the said tuples:
(6, 9, 8, 6)
Programs of Functions:
4. Write a Python function that takes two lists and returns True if they
have at least one common member.
5. Write a Python function that accepts a string and counts the number
of upper and lower case letters.
Sample Input : 'The quick Brow Fox'
Expected Output :
No. of Upper case characters : 3
No. of Lower case Characters : 12
UNIT-4
2. Write a Python program to open the file "sample.txt" and print its
content line by line.
3. Open the "sample.txt" file in append mode and add the following lines
to it:
5. Create a new file named "numbers.txt" and write the numbers 1 to 10,
each on a new line.