0% found this document useful (0 votes)
6 views4 pages

Assignment (XII CS) File Handling Dated 01-08-2024

Uploaded by

rockysa658
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Assignment (XII CS) File Handling Dated 01-08-2024

Uploaded by

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

Kamal Model Sr Sec School

XII Computer Sc.


Chapter-File Handling
Assignment dated 01.08.2024
Sr. Questions
No
1 Which pickle module method is used to write a Python object to a
binary file?
a. save()
b. serialize()
c. store()
d. dump()
2 Which of the following file opening mode in Python, generates an
error if the file does not exist?
a. a
b. r
c. w
d. w+
3 The correct syntax of seek() is:
a. file_object.seek(offset [, reference_point])
b. seek(offset [, reference_point])
c. seek(offset, file_object)
d. seek.file_object(offset)
4 ASSERTION AND REASONING based question.
Mark the correct choice as
(a) Both A and R are true and R is the correct explanation for A
(b) Both A and R are true and R is not the correct explanation for A
(c) A is True but R is False
(d) A is false but R is True

Assertion (A): A binary file in python is used to store collection


objects like lists and dictionaries that can be later retrieved in their
original form using pickle module.
14
Reasoning (A): Binary files are just like normal text files and can be
read using a text editor like Notepad.
5 Write a function COUNT() in Python to read from a text file

'Gratitude.txt' and display the count of the letter 'e' in each


line
Example: If the file content is as follows:
Gratitude is a humble heart's radiant glow,
A timeless gift that nurtures and bestows.
It's the appreciation for the love we're shown,
In moments big and small, it's truly known.

The COUNT() function should display the output as:


Line 1 : 3

Line 2 : 4

Line 3 : 6

Line 4 : 1
6 Write a function Start_with_I() in Python, which should read a

text file 'Gratitude.txt' and then display lines starting with 'I'.
Example: If the file content is as follows:
Gratitude is a humble heart's radiant glow,
A timeless gift that nurtures and bestows.
It's the appreciation for the love we're shown,
In moments big and small, it's truly known.

37
Then the output should be
It's the appreciation for the love we're shown,

In moments big and small, it's truly known.


7 Create a function maxsalary() in Python to read all the records
from an already existing file record.csv which stores the records
of various employees working in a department. Data is stored under
various fields as shown below:
E_code E_name Scale Salary
A01 Bijesh Mehra S4 65400
B02 Vikram Goel S3 60000
C09 Suraj Mehta S2 45300
…… …… …… ……

Function should display the row where the salary is maximum.


Note: Assume that all employees have distinct salary.
8 Consider a binary file 'INVENTORY.DAT' that stores information

about products using tuple with the structure (ProductID,

ProductName, Quantity, Price). Write a Python function

expensiveProducts() to read the contents of

'INVENTORY.DAT' and display details of products with a price


higher than Rs. 1000. Additionally, calculate and display the total
count of such expensive products.
For example: If the file stores the following data in binary format
(1, 'ABC', 100, 5000)
(2, 'DEF', 250, 1000)
(3, 'GHI', 300, 2000)
then the function should display
Product ID: 1

Product ID: 3

Total expensive products: 2

You might also like