XII Comp Sc
XII Comp Sc
2024 - 2025
Subject: Computer Science (083) Time : 1 Hour
Class : XII Max. Marks: 30
Name : ________________________ Roll No.: ______ Invigilators Signature _______________
GENERAL INSTRUCTIONS :
Group-A [1*10=10]
1. Which of the following is a correct way to handle exceptions in Python?
a) try-catch-finally b) try-except-finally
c) try-except-else d) try-finally-catch
2. Which one of the following is not a correct python statement to open a text file “student.txt”
to write context into it?
a) F=open(‘student.txt’,’w’) c) F=open(‘student.txt’,’a’)
b) F=open(‘student.txt’,’A’) d) F=open(‘student.txt’,’w+’)
1
a) The* b) Dock*The*the*clock c) Dock*the*clock d)Error
4. What is the purpose of the “with statement” when working with files?
a) To open the file in read mode c) To open the file in write mode
b) To ensure that the file is closed properly after use. d) To manipulate the data in the
file
5. Which method is used to write a single line of text in a file?
a) write() b) writelines() c) read() d) readline()
6. If the following is used to read the contents of a text file object F:
X=F.readlines()
Which of the following is the correct data type of X?
a) string b) list c) tuple d) dictionary
7. What will be the output of the following code?
try:
x=1/0
except ZeroDivisionError:
print("ZeroDivisionError caught")
finally:
print("Finally block executed")
a) ZeroDivisionError caught
b) Finally block executed
c) ZeroDivisionError caught Finally block executed
d) ZeroDivisionError caught (No Finally block executed)
8. What does the pickle.dump() function do?
a) it reads an object from a binary file.
b) it writes an object to a binary file.
c) it serializes an object to a text file.
d) it deserializes an object from a text file.
9. Raghav is trying to write a tuple tup1 = (1,2,3,4,5) on a binary file test.bin. Consider the
following code written by him.
import pickle
tup1 = (1,2,3,4,5)
myfile = open("test.bin",'wb')
pickle._______ #Statement 1
myfile.close()
Identify the missing code in Statement 1.
a. dump(myfile,tup1) b. dump(tup1, myfile)
c. write(tup1,myfile) d. load(myfile,tup1)
2
(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
10. Assertion (A): CSV (Comma Separated Values) is a file format for data storage which
looks like a text file.
Reason (R): The information is organized with one record on each line and each field is
separated by comma.
Group-B [2*4=8]
11. Write a method in python to read lines from a text file INDIA.TXT, to find and display the
occurrence of the word “India”.
Consider the file “INDIA.TXT” containing the following:
“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.”
13. Suppose content of 'Myfile.txt' is Culture is “the widening of the mind and of the spirit”.
What will be the output of the following code?
myfile = open("Myfile.txt")
x = myfile.read()
y = x.count('the')
print(y)
myfile.close()
14. Write down the use of tell() and seek() function with respect to a binary file.
Group-C [3*4=12]
15. A binary file “STUDENT.DAT” has structure (Admission_number, Name, and Percentage).
Write a function count() in python that would read the contents from the binary file and
display the details of those students whose percentage is below 80. Also display number
of students scoring below 80%.
16. Write a function, copyData(), that reads contents from the file SPORT.DAT and copies the
records with Sport name as “Basket Ball” to the file named BASKET.DAT. The function
should return the total number of records copied to the file BASKET.DAT.
17. Write a program to create a CSV file to store student data (Rollno, Name, Marks). Obtain
data from user and write 5 records into the file.
3
18. Madhwan, is doing internship in “SQUARE Solutions Pvt. Ltd.”. He wrote the following
python code to store student’s data in csv file (Student.csv) handling. Unfortunately, he
forgot some steps of the python code. Please help him to create a CSV File 'Student.csv'
by completing the code.
3, SHREEVALI, XII, A
4, BHOOMI, XI, A
5, SWARIT, XII, A
import csv
csvfh = open("Student.csv","w", newline='')
stuwriter = csv._____ #Statement-1
data = []
header = ['ROLL_NO', 'NAME', 'CLASS', 'SECTION']
data.append(header)
for i in range(5):
roll_no = int(input("Enter Roll Number : "))
name = input("Enter Name : ")
Class = input("Enter Class : ")
4
B. Identify the suitable code for Statement-2 : [1]
a) 'ROLL_NO', 'NAME', 'CLASS', 'SECTION' c) 'roll_no','name','Class','section'
b) ROLL_NO, NAME, CLASS, SECTION d) roll_no,name,Class,section
C. Choose the function name that should be used for Statement-3 to create the desired CSV
File. [1]