Python Programming
Assignment 3
Note: 1) The submission date for this assignment is 10/04/2026.
2) This assignment is to be written on A4 sheets only.
3) Please try to write the answers to subjective questions in your own words.
4) Write codes for programming questions in Python only using proper syntax.
1) Discuss the steps involved in reading data from a file and writing data to another file.
2) What is recursion? Explain with an example where recursion is more suitable than iteration.
3) Create a function that accepts a list of tuples, where each tuple contains a student’s name and
marks in three subjects. The function should:
● Calculate the total and average marks.
● Return a dictionary with student names as keys and averages as values.
● Display names of students (in title case) and average marks up to 2 decimal
● places scoring above 75% using a set.
4) Compare lists, tuples, sets and dictionaries in Python in terms of mutability, declaration, order,
duplicacy and accessing elements using a loop.
5) Explain the concept of parameter passing in Python functions (positional, keyword, default, and
variable-length arguments).
6) Differentiate between text files and binary files in Python. Give examples of situations where
each should be used.
7) Explain how a Python file objects work along with a diagram and type details for both types of
files.
8) Discuss the importance of closing a file properly. What happens if a file is not closed after
performing write operations?
9) Explain the working of the seek() and tell() methods in Python. Provide a scenario where
manipulating the file pointer is useful.
10) Write a program that opens a text file and counts the total number of words present in it.
Print the result.