You are on page 1of 2

Worksheet

1. Define two functions which, respectively, input values for the elements of lists
of reals and output the list elements:
2. Write a Python function to sum all the numbers in a list.
Sample List : (8, 2, 3, 0, 7)
Expected Output : 20
3. Write a Python program to read a file line by line and store it into a list.
4. Write a Python function that accepts a string and calculate the number of upper case letters
and lower case letters.
Sample String : 'The quick Brow Fox'
Expected Output :
No. of Upper case characters : 3
No. of Lower case Characters : 12
5. Write a Python program to assess if a file is closed or not.
6. Write a Python program to combine each line from first file with the corresponding line in
second file.
7. Write a Python function to find the middle character(s) of a given string. If the length of the
string is odd return the middle character and return the middle two characters if the string
length is even.
Sample Input:
("Python")
("PHP")
("Java")
Sample Output:
th
H
av
8. Write a Python function that takes a list and returns a new list with unique elements of the
first list.
Sample List : [1,2,3,3,3,3,4,5]
Unique List : [1, 2, 3, 4, 5]
9. Write a Python function that accepts a string and calculate the number of upper case letters
and lower case letters.
Sample String : 'The quick Brow Fox'
Expected Output :
No. of Upper case characters : 3
No. of Lower case Characters : 12
10. Write a function in python to read the content from a text file "software.txt" line by line and
display the same on screen.
11. Write a Python program to generate a random alphabetical character, alphabetical string and
alphabetical string of a fixed length.
12. Write a Python program to generate a random integer between 0 and 6 - excluding 6, random
integer between 5 and 10 - excluding 10, random integer between 0 and 10, with a step of 3
and random date between two dates. Use random.randrange()
13. Write a Python program to check if a function is a user-defined function or not. Use
types.FunctionType, types.LambdaType()
14. Write a Python program to read and display the content of a given CSV file. Use csv.reader

You might also like