CS_Class_Test_XII_20-08-2022
CS_Class_Test_XII_20-08-2022
CS_Class_Test_XII_20-08-2022
Class Test (Sub: Computer Science, Class: XII) (Marks: Q1 to 13: 1 marks, Q14,15: 2 marks,
Q16:3marks)
1 Which of the following option is not correct?
a. if we try to read a text file that does not exist, an error occurs.
b. if we try to read a text file that does not exist, the file gets created.
c. if we try to write on a text file that does not exist, no error occurs.
d. if we try to write on a text file that does not exist, the file gets created.
2 Which of the following options can be used to read the first line of a text file Myfile.txt?
a. myfile = open('Myfile.txt'); myfile.read()
b. myfile = open('Myfile.txt','r'); myfile.read(n)
c. myfile = open('Myfile.txt'); myfile.readline()
d. myfile = open('Myfile.txt'); myfile.readlines()
3 Assume that the position of the file pointer is at the beginning of 3rd line in a text file. Which
of the following option can be used to read all the remaining lines?
a. myfile.read()b. myfile.read(n)c. myfile.readline()d. myfile.readlines()
4 A text file student.txt is stored in the storage device. Identify the correct option out of the
following options to open the file in read mode.
i. myfile = open('student.txt','rb')ii. myfile = open('student.txt','w')
iii. myfile = open('student.txt','r')iv. myfile = open('student.txt')
a. only I b. both i and ivc. both iii and ivd. both i and iii
5 Which of the following statement is incorrect in the context of binary files?
a. Information is stored in the same format in which the information is held in
memory.
b. No character translation takes placec. Every line ends with a new line character
d. pickle module is used for reading and writing
6 What is the significance of the tell() method?
a. tells the path of fileb. tells the current position of the file pointer within the file
c. tells the end position within the filed. checks the existence of a file at the desired location
7 Which of the following statement is true?
a. pickling creates an object from a sequence of bytesb. pickling is used for object serialization
c. pickling is used for object deserialization
d. pickling is used to manage all types of files in Python
8 Syntax for opening Student.csv file in write mode is
myfile = open("Student.csv","w",newline='').
What is the importance of newline=''?
a. A newline gets added to the fileb. Empty string gets appended to the first line.
c. Empty string gets appended to all lines.d. EOL translation is suppressed
9 Which of the following is not a function / method of csv module in Python?
a. read()b. reader()c. writer()d. writerow()
10 Which of the following statement opens a binary file record.bin in write mode and writes
data from a list lst1 = [1,2,3,4] on the binary file?
a. with open('record.bin','wb') as myfile:
pickle.dump(lst1,myfile)
b. with open('record.bin','wb') as myfile:
pickle.dump(myfile,lst1)
c. with open('record.bin','wb+') as myfile:
pickle.dump(myfile,lst1)
d. with open('record.bin','ab') as myfile:
pickle.dump(myfile,lst1)
11 Suppose content of 'Myfile.txt' is:
Twinkle twinkle little star
How I wonder what you are
Up above the world so high
Like a diamond in the sky
What will be the output of the following code?
myfile = open("Myfile.txt")
data = myfile.readlines()
print(len(data))
myfile.close()
12 Suppose content of 'Myfile.txt' is
Honesty is the best policy.
What will be the output of the following code?
myfile = open("Myfile.txt")
x = myfile.read()
print(len(x))
myfile.close()
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 Suppose content of 'Myfile.txt' is
Ek Bharat Shreshtha Bharat
What will be the output of the following code?
myfile = open("Myfile.txt")
vlist = list("aeiouAEIOU")
vc=0
x = myfile.read()
for y in x:
if(y in vlist):
vc+=1
print(vc)
myfile.close()
15 Assume the content of text file, 'student.txt' is:
Arjun Kumar
Ismail Khan
Joseph B
Hanika Kiran
What will be the data type of data_rec?
myfile = open("Myfile.txt")
data_rec = myfile.readlines()
myfile.close()
a. stringb. listc. tupled. dictionary
16 Write a function AMCount() in Python, which should read each character of a text file STORY.TXT,
should count and display the occurrence of alphabets A and M (including small cases a and m too).
Example:
If the file content is as follows:
Updated information
As simplified by official websites.
The EUCount() function should display the output as:
A or a:4
M or m :2