Thanks to visit codestin.com
Credit goes to www.scribd.com

100% found this document useful (1 vote)
63 views2 pages

File Handling Worksheet1

This document is a revision worksheet for Computer Science (083) for Grade XII, focusing on file handling in Python. It contains a series of programming tasks that require writing functions to manipulate and analyze text and binary files, including counting specific words, reading records, and filtering data based on conditions. The tasks aim to enhance students' understanding of file operations and data processing in Python.

Uploaded by

Deepti Korde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
63 views2 pages

File Handling Worksheet1

This document is a revision worksheet for Computer Science (083) for Grade XII, focusing on file handling in Python. It contains a series of programming tasks that require writing functions to manipulate and analyze text and binary files, including counting specific words, reading records, and filtering data based on conditions. The tasks aim to enhance students' understanding of file operations and data processing in Python.

Uploaded by

Deepti Korde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

REVISION WORKSHEET 2022-23

Subject: Computer Science(083) Grade: XII


Topic: File handling Time:
Name: ___________ Date:

Q.No. Question Description Marks


1. Write a function in Python that counts the number of “Me” or “My” (in smaller case
also) words present in a text file “STORY.TXT”. If the “STORY.TXT” contents are as
follows:
My first book was Me and My Family. It gave me chance to be Known to the world.
The output of the function should be: Count of Me/My in file: 4

2. Write a function AMCount() in Python, which should read each character of a text
file STORY.TXT, should count and display the occurence of alphabets ‘A’ and ‘M’
(including small cases ‘a’ and ‘m ‘too). Example: If the file content is as follows:
The AMCount() function should display the output as: A or a = 4, M or m =2
3. Write a function in python to count the number of lines in a text file ‘STORY.TXT’
which is starting with an alphabet ‘A’ .
4. Write a method/function DISPLAYWORDS() in python to read lines from a text file
STORY.TXT, and display those words, which are less than 4 characters.
5. Write a function RevText() to read a text file “ Story.txt “ and Print only word
starting with ‘I’ in reverse order . Example: If value in text file is: INDIA IS MY
COUNTRY Output will be: AIDNI SI MY COUNTRY.
6. Write a function in python to count the number of lowercase alphabets present in a
text file “Story.txt”
7. Write a user-defined function named count() that will read the contents of text file
named “Story.txt” and count the number of lines which starts with either “I‟ or
“M‟. E.g. In the following paragraph, there are 2 lines starting with “I‟ or “M‟:
“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.”
8. Write a function countmy( )in Python to read the text file “Story.txt” and count the
number of times “my” or “My” occurs in the file. For example if the file “Story.TXT”
contains:
“This is my website. I have displayed my preferences in the CHOICE section.”
The countmy( ) function should display the output as: “my occurs 2 times”.
9 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%.
10. Write a function addrec() in Python to add more new records at the bottom of a
binary file “STUDENT.dat”, assuming the binary file is containing the following
structure :
[Roll Number, Student Name]

Page 1 of 2
11. Write a function routechange(route number) which takes the Route number as
parameter and modify the route name(Accept it from the user) of passed route
number in a binary file “route.dat”.
12. A binary file “salary.DAT” has structure [employee id, employee name, salary].
Write a function countrec() in Python that would read contents of the file
“salary.DAT” and display the details of those employee whose salary is above
20000.

13. Amit is a monitor of class XII-A and he stored the record of all the students of his
class in a file named “class.dat”. Structure of record is [roll number, name,
percentage]. His computer teacher has assigned the following duty to Amit
Write a function remcount( ) to count the number of students who need remedial
class (student who scored less than 40 percent)

14. Write a program to search the record from “data.csv” according to the admission
number input from the user. Structure of record saved in “data.csv” is Adm_no,
Name, Class, Section, Marks

15 Write a program to read all content of “student.csv” and display records of only
those students who scored more than 80 marks. Records stored in students is in
format : Rollno, Name, Marks

16 Write a program to display all the records from product.csv whose price is more
than 300. Format of record stored in product.csv is product id, product name, price,.

Page 2 of 2

You might also like