Vellamal Bodhi Campus Vellore: Worksheet File Handling Marks
Vellamal Bodhi Campus Vellore: Worksheet File Handling Marks
Section E
1. Write a function to read the content from the file “India.txt”, and store the
frequency of each word in dictionary and display the dictionary in the screen.
Content of the file is: ‘‘India is the fastest growing economy. India is looking for
more investments around the globe. The whole world is looking at India as a
great market. Most of the Indians can foresee the heights that India is capable
of reaching.’’ Output of the file: {‘India’: 4, ‘is’: 4, ‘the’: 4, ‘fastest’: 1, ‘growing’:
1, ‘economy.’: 1, ‘looking’: 2, ‘for’: 1, ‘more’: 1, ‘investments’: 1, ‘around’: 1,
‘globe.’: 1, ‘The’: 1, ‘whole’: 1, ‘world’: 1, ‘at’: 1, ‘as’: 1, ‘a’: 1, ‘great’: 1,
‘market.’: 1, ‘Most’: 1, ‘of’: 2, ‘Indians’: 1, ‘can’: 1, ‘foresee’: 1, ‘heights’: 1, ‘that’:
1, ‘capable’: 1, ‘reaching.’: 1}
2. Write a function to read the content from the file “India.txt”, and store the
frequency of each character in dictionary and display the dictionary in the
screen. Content of the file is: ‘‘India is the fastest growing economy. India is
looking for more investments around the globe. The whole world is looking at
India as a great market. Most of the Indians can foresee the heights that India is
capable of reaching.’’ Output is: {'I': 5, 'n': 15, 'd': 7, 'i': 15, 'a': 17, ' ': 39, 's': 13,
't': 15, 'h': 10, 'e': 20, 'f': 5, 'g': 8, 'r': 9, 'o': 17, 'w': 3, 'c': 4, 'm': 4, 'y': 1, '.': 4, 'n':
4, 'l': 6, 'k': 3, 'v': 1, 'u': 1, 'b': 2, 'T': 1, 'M': 1, 'p': 1}
3. Write a function addrecord() a add new record to the binary file “student” using
list. The list should consist of student number, student name and marks of the
student.
4. Write a function readall() the record from the binary file “student” and display all
the records
5. Write a function search () to search a record in a binary file according to the
student number entered by the user. Also display the message “Record not
found” in case record not found in the file.
6. Write a function update () to update the record in the binary file “student”, which
consist of student number, student name and marks. The updation should be
done on the basis of student number entered by the user.
7. Write a function delrecord() to delete the record form the binary file “student”.
The record should be deleted on the basis of student number.
Page 1
8. Write a menu driven program to do the following option on binary file “Student”.
The program should implement through list which contains student number,
student name and marks. Student Menu ------------------ 1) Add New Student 2)
Display student details 3) Search student 4) Update a Record 5) Delete a Record
6) Save & Quit
9. Write a program to count no. of records in csv file and display the records in
tabular form. Admno, Name, Eng, Hindi, Maths, Sci, Ssc 1101 1102 1103 1104
1105 Tejas Swati Sam Imran Heena 80 90 90 75 85 85 85 80 76 90 95 94 64 80 90
94 96 85 80 75 86 80 70
10. Write a function AverageColumn() which accepts csv file as parameter. It will
print sum and average of each row. For example if marks.csv contain
50,60,70,80,90 70,60,50,60,80 50,60,70,80,90 Then OUTPUT will be Sum is : 350.0
Average is : 116.66666666666667 Sum is : 320.0 Average is : 106.66666666666667
Sum is : 350.0 Average is : 175.0
11. Aarti is new in python data-handling. Please help her to count the number of
lines which begins with ‘W’ or ‘w’ in poem.txt.
----- -----
Page 2