2024 08 06 09 59 Solution

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

VELLAMAL BODHI CAMPUS VELLORE

Date : 06-08-2024 STD 12 Science Computer Science Total Marks : 30


worksheet file handling 4marks

Section D

* Answer The Following Questions In Brief.[5 Marks Each] [30]

1. Mr. Iqbal is a programmer, who has recently joined the company and 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)

Ans. : (a) import pickle


(b) stud.dat
(c) file.tell()
(d) file.seek(pos)
(e) pickle.dump(st,file)
(f) (iii) pickle.dump(LST,FILE)

2. Mr. Mathew is a programmer, who has recently joined the company and given
a task to write a python code to perform update operation in binary file
(stud.dat) which contain admno (Admission No) and fee(Fee paid by student).
He has succeeded in writing partial code and has missed out certain statements,
You as an expert of Python have to provide the missing statements.

(a)

Page 1
Ans. : (a) import pickle
(b) stud.dat
(c) file.tell()
(d) file.seek(pos)
(e) pickle.dump(st,file)
(f) (iii) pickle.dump(LST,FILE)

3. You are a student in CBSE School. Teacher has 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)

Ans. : (a)Statement 1 : student = []


(b) Statement 2 : stu = pickle.load(f)
(c)Statement 3 : student.append(s)
(d) Statement 4 : wb
(e) Statement 5 : if i[0] == r: (f) Statement 6 : break

4. Dhruv Kumar of class 12 is writing a program to create a CSV file “Teacher.csv”


which will store the teacher information entered by user. He has written the
following code. As a programmer, help him to successfully execute the given
task. Write appropriate statement / function/ code against fill ups.

Ans. : (a) Line 1 : import csv


(b) Line 2 with open("LAPS_Teacher12.csv" , "a", newline="") as file:
(c) Line 3 : Write = csv.writer(file)
(d) LST.append([ID1,Name1,Subject])
(e) Write.writerow(LST)

Page 2
5. Krishna of class 12 is writing a program to read the details of Sports
performance and store in the csv file “games.csv” delimited with a tab
character. As a programmer, help him to achieve the task.

(a)Line 1 : Name the module he should import.


(b)Line 2 : To create an object to enable to write in the csv file.
(c)Line 3 : To store the data in list
(d)Line 4 : To write a record.
(e)Line 5 : To close the file.

Ans. : (a)Line 1 : Import csv


(b) Line 2 : csv.writer
(c)Line 3 : rec=[sport,comp,prize]
(d) Line 4 : wobl.writerow(rec)
(e) Line 5 : f.close()

6. Krishna is confused in Python code given below. Please help him to answer the
following questions.

Page 3
(a) Which line in the above code check for capital letter?
(b) Which line in the above code read the file “story. txt”?
(c) Which line in the above code does not affect the execution of program?
(d) Which line is the above code coverts capital letter to small letter?
(e) Which line is the above code opens the file in write mode?
(f) Which line is the above code saves the data?
(g) Which line(s) is/are the part of selection statement.
(h) Which line(s) is/are used to close story1.txt?

Ans. :
(a) Line 6 (e) Line 2
(b) Line 4 (f) Line 13
(c) Line 10 (g) Line 6, Line 8 and Line 11
(d) Line 7 (h) Line 15
----- -----

You might also like