Summer Vacation Task May June23
Summer Vacation Task May June23
Summer Vacation Task May June23
Submitted By
Mr. Praveen MJ
PGT (CS)
SAINIK SCHOOL AMARAVATHINAGAR
SUMMER VACATION TASK May – June 2023
CLASS XII
FILE HANLDING PROGRAMS
(TEXT FILES)
01. Write a Python program to read an entire text file.
02. Write a Python program to read first n lines of a file.
03. Write a Python program to append text to a file and display the text.
04. Write a Python program to read last n lines of a file.
05. Write a Python program to read a file line by line and store it into a list.
06. Write a Python program to read a file line by line store it into a variable.
07. Write a Python program to read a file line by line store it into an array.
08. Write a python program to find the longest words.
09. Write a Python program to count the number of lines in a text file.
10. Write a Python program to count the frequency of words in a file.
11. Write a Python program to get the file size of a plain file.
12. Write a Python program to write a list to a file.
13. Write a Python program to copy the contents of a file to another file .
14. Write a Python program to combine each line from first file with the corresponding line in second file.
15. Write a Python program to read a random line from a file.
16. Write a Python program to assess if a file is closed or not.
17. Write a Python program to remove newline characters from a file.
18. Write a Python program that takes a text file as input and returns the number of words of a given text file.
Note: Some words can be separated by a comma with no space.
19. Write a Python program to extract characters from various text files and puts them into a list.
20. Write a Python program to generate 26 text files named A.txt, B.txt, and so on up to Z.txt.
21. Write a Python program to create a file where all letters of English alphabet are listed by specified number of letters on each
line.
22. Write a program to read the text file “abc.txt” and return the 10 first characters of the file
23. Write a program to read 1st line from “abc.txt” and display on screen.
24. Modify the above program and read entire file using readline function
25. Modify the above program by adding end parameter in print statement
26. Write a program in Python to read lines from a text file NOTES.TXT, count and print those lines, which are ending with ‘.’ or
‘,’ For eg. if the file contains : In Python, a file operation takes place in the following order:
(i) Open a file. (ii) Read or write, (iii) Close the file.
output : count=3
FILE HANLDING PROGRAMS
(BINARY FILES)
1 Write a program to create a list L and store it to binary file “test”
2 Write a program to create a list L and store it to binary file “test”
3 Write a program to create pickle file “test” where
(i) write data to pickle file using Dictionary. (ii) read the file and display the contents
4. Write a program to create pickle file “test” where
(i) write data to pickle file using Dictionary. (ii) read the file and display the contents
5.Write program to read the above created ‘student’ file and show the contents of file in the following format roll name total
6. Write a program to search for the details (name,total) of student which roll no is read during the execution of the program.
7. Write a program to update the file with a new value of Name. The values of name and rollno are read during the execution of
the program.
8. Write a program to delete record from pickle file “student”. The value of rollno is taken from user.
9. Write a menu driven program to add, delete, display, modify records in pickle files “emp” using dictionary and functions.
Fields of employee file are :
empno :Empolyee number
name : Name of Employee
salary : Salary of Employee
Bonus : 10% of salary
10. Write a function in Python to search and display details of all those students using display(L) function, whose stream is
“HUMANITIES” from pickled file “Student.dat”. Assuming the pickled file is containing the following
fields :RNO,Name,Stream,Per
11. write a method store_data(record) in python to write the content in a pickled file member.dat.
Considering the following definition of functions, write a method inPython to search and display the content in a pickled file
FACTORY.DAT,where FCTID is matching with the value ‘105’
12. A binary file “STUDENT.DAT” has structure (admission_number, Name, Percentage). Write a function countrec() in Python
that would read contents of the file “STUDENT.DAT” and display the details of those students whose percentage is above 75.
Also display number of students scoring above 75%
A binary file “Book.dat” has structure [BookNo, Book_Name, Author, Price].
(i) Write a user defined function CreateFile() to input data for a record and add to Book.dat .
(ii) Write a function CountRec(Author) in Python which accepts the Author name as parameter and count and Goyal return
number of books by the given Author are stored in the binary file “Book.dat”
13. Write a definition for function Billing() in Python to read each record of a pickled file STOCK.DAT, and display the Total Price
of all the records in the file. Assume that the file STOCK.DAT is containing following fields SName and Price
A pickled file ELECTION.DAT contains records stored the following fields :Name,Count Write the definition for function
LowCount() in Python, which reads every record from ELECTION.DAT and displays every such Name whose Count is less than 10
14. Write a method/function MERIT() in python to search and display all the content from a pickled file STUDENT. DAT, where
Marks of STUDENT is more than 75.File containing Name and Marks fields.
15. Write a method/function MERIT() in python to search and display all the content from a pickled file STUDENT. DAT, where
Marks of STUDENT is more than 75.File containing Name and Marks fields.
16. Write a method/function SPLDOCS() in python to search and display all the content from a pickled file DOCS. DAT, where
Specialisation of DOCTORS is “CARDIOLOGY”
17. Amritya Seth is a programmer, who has recently been given a task to write a python code to perform the following binary
file operations with the help of two user defined functions/modules
(a) AddStudents() to create a binary file called STUDENT.DAT containing student information – roll number, name and marks
(out of 100) of each student.
(b) GetStudents() to display the name and percentage of those students who have a percentage greater than 75. In case there is
no student having percentage > 75 the function displays an appropriate message. The function should also display the average
percent.
Solve the last five years CBSE Question papers (covered Chapters – Python Revision
Tour 1 & 2, Functions and File Handling Chapters)