1
KAMARAJ INTERNATIONAL ACADEMY SENIOR SECONDARY SCHOOL (CBSE)
AFFILIATED TO CBSE, NEW DELHI. AFFILIATION NO: 1931446
PASUVANTHUNAI ROAD, PANDAVARMANGALM, KOVILPATTI- 62850
DATE: 12.09.24 CLASS: XII COMPUTER SCIENCE (083)
REVISION WORKSHEET PT -3
Answer the following Questions:
1. A binary file “Book.data” has structure [Book No, Book_Name, Author, Price]
Write a user-defined function CreateFile() to input data for a record and add to ‘Book.dat’.
Also write a function CountRec(Author) in python which accepts the Author name as a
parameter and count and return number of books by the given Author are stored in the
binary file “Book.dat”.
2. Write a method in python to read lines from a text file “DIARY.TXT” and display those
lines which start with the alphabet ‘P’
3. Write a function to count the “me” and “my” in a file “India.txt”.
4. What do you mean by file? What do you mean by file handling?
5. Explain open() function with its syntax in detail.
6. Does python create itself if the file doesn’t exist in the memory? Illustrate your answer with
an example.
7. Write a statement to create a data.txt file with the following text.
8. List out the basic file modes available in python.
9.Write a python program to create and read the city.txt file in one go and print the contents on
the output screen.
11. Consider following lines for the file friends.txt and predict the output:
Friends are crazy, Friends are naughty !
Friends are honest, Friends are best !
Friends are like keygen, friends are like license key !
We are nothing without friends, Life is not possible without friends !
f = open("friends.txt")
l = f.readline()
l2 = f.readline(18)
ch3=f.read(10)
print(l2)
print(ch3)
print(f.readline())
f.close()
12. Write a function count_lines() to count and display the total number of lines from the
file. Consider above file – friends.txt.
13. Write a function display_oddLines() to display odd number lines from the text file.
Consider above file – friends.txt.
14. Write a function cust_data() to ask user to enter their names and age to store data in
customer.txt file.