150+ Best MCQ File Handling in Python Class 12

Share with others

File Handling in Python Class 12 MCQ

File Handling in Python Class 12
File Handling in Python Class 12

Q1. Which statement will read 5 characters from a file(file object ‘f’)?

a. f.read()

b. f.read(5)

c. f.reads(5)

d. None of the above

Q2. Which function open file in python?

a. open( )

b. new( )

c. Open( )

d. None of the above

Q3. Processing of Text file is faster than binary files.(T/F)

a. True

b. False

Q4. Which mode create new file if the file does not exist?

a. write mode

b. append mode

c. Both of the above

d. None of the above

Q5. Which statement will return one line from a file (file object is ‘f’)?

a. f.readline( )

b. f.readlines( )

c. f.read( )

d. f.line( )

File Handling in Python Class 12 MCQ

Q6. readlines() method return _________

a. String

b. List

c. Dictionary

d. Tuple

Q7. EOF stands for _________________

a. End of File

b. End off File

c. End on File

d. End or File

Q8. Which function is used to read data from Text File?

a. read( )

b. writelines( )

c. pickle( )

d. dump( )

Q9. Which of the following will read entire content of file(file object ‘f’)?

a. f.reads( )

b. f.read( )

c. f.read(all)

d. f.read( * )

Q10. Which symbol is used for append mode?

a. ap

b. a

c. w

d. app

File Handling in Python Class 12 MCQ


Click here to check your performance in file handling in python class 12

File Handling in Python Class 12 MCQ

Q11. Which of the following options can be used to read the first line of a text file data.txt?

a. f = open(‘data.txt’); f.read()

b. f = open(‘data.txt’,’r’); f.read(n)

c. myfile = open(‘data.txt’); f.readline()

d. f = open(‘data.txt’); f.readlines()

Q12. File in python is treated as sequence of ________________

a. Bytes

b. Bites

c. bits

d. None of the above

Q13. Which function is used to write data in binary mode?

a. write

b. writelines

c. pickle

d. dump

Q14. Which function is used to force transfer of data from buffer to file?

a. flush( )

b. save( )

c. move( )

d. None of the above

Q15. Let the file pointer is at the end of 3rd line in a text file named “data.txt”. Which of the following option can be used to read all the remaining lines?

a. f.read( )

b. f.read(all)

c. f.readline( )

d. f.readlines( )

File Handling in Python Class 12 MCQ

Q16. ____________________ module is used for serializing and de-serializing any Python object structure.

a. pickle

b. unpickle

c. pandas

d. math

Q17. Which of the following error is returned when we try to open a file in write mode which does not exist?

a. FileNotFoundError

b. FileFoundError

c. FileNotExistError

d. None of the above

Q18. ______________ function returns the strings.

a. read( )

b. readline( )

c. Both of the above

d. None of the above

Q19. The syntax of seek() is: file_object.seek(offset [, reference_point])

What is reference_point indicate?

a. reference_point indicates the starting position of the file object

b. reference_point indicates the ending position of the file object

c. reference_point indicates the current position of the file object

d. None of the above.

Q20. Identify the invalid mode from the following.

a. a

b. r+

c. ar+

d. w

File Handling in Python Class 12
File Handling in Python Class 12

Q21. Which of the following is an invalid mode of file opening?

a. read only mode

b. write only mode

c. read and write mode

d. write and append mode

Q22. readlines( ) function returns all the words of the file in the form of List. (T/F)

a. True

b. False

Q23. What is ‘f’ in the following statement?

f=open("Data.txt" , "r")

a. File Name

b. File Handle

c. Mode of file

d. File Handling

Q24. What is full form of CSV

a. Comma Separation Value

b. Comma Separated Value

c. Common Syntax Value

d. Comma Separated Variable

Q25. Which statement will open file “data.txt” in append mode?

a. f = open(“data.txt” , “a”)

b. f = Open(“data.txt” , “ab”)

c. f = new(“data.txt” , “a”)

d. open(“data.txt” , “a”)

File Handling in Python Class 12 MCQ

Q26. Fill in the blank



import pickle
f=open("data.dat",'rb')
d=_____________________.load(f)
f.close()

a. unpickle

b. pickling

c. pickle

d. pick

Q27. Which module to be imported to make the following line functional?

sys.stdout.write("ABC")

a. system

b. sys

c. stdout

d. stdin

Q28. What error is returned by the following statement if the file does not exist?

f=open("A.txt")

a. FileNotFoundError

b. NotFoundError

c. FileNotFound

d. FoundError

Q29. Which statement will return error?

import pickle
f=open("data.dat",'rb')
d=pickle.load(f)
f.end()

a. Statement 1

b. Statement 2

c. Statement 3

d. Statement 4

Q30. Which of the following function takes two arguments?

a. load( )

b. dump( )

c. both of the above

d. none of the above

File Handling in Python Class 12 MCQ


Click here to check your performance in file handling in python class 12

File Handling in Python Class 12 MCQ

Q31. Almost all the files in our computer stored as _______ File.

a. Text

b. Binary

c. CSV

d. None of the above

Q32. Binary files are not in human readable format.(T/F)

a. True

b. False

Q33. .pdf and .doc are examples of __________ files.

a. Text

b. Binary

c. CSV

d. None of the above

Q34. The syntax of seek() is:file_object.seek(offset [, reference_point]) What all values can be given as a reference point?

a. 1

b. 2

c. 0

d. All of the above

Q35. There is no delimiter to end a line in binary files.(T/F)

a. True

b. False

File Handling in Python Class 12 MCQ

Q36. seek( ) method is used for random access to the file.(T/F)

a. True

b. False

Q37. Fill in the blanks in the following code of writing data in binary files. Choose the answer for statement 1

import ___________   # Statement 1
rec = [ ]
while True:
     rn = int(input("Enter"))
     nm = input("Enter")
     temp = [rn, nm]
     rec.append(temp)
     ch = input("Enter choice (Y/N)")
     if ch.upper == "N":
          break
f = open("stud.dat", "____________")  #statement 2
__________ .dump(rec, f)   #statement 3
_______.close( ) # statement 4

a. csv

b. unpickle

c. pickle

d. load

Q38. Refer to the above code and choose the option for statement2.

a. w

b. w+

c. wb

d. write

Q39. Refer to the above code (Q 38)and choose the option for statement 3

a. unpickle

b. write

c. pickle

d. None of the above

Q40. Refer to the above code (Q 38)and choose the option for statement 4.

a. f

b. rec

c. file

d. stud

File Handling in Python Class 12
File Handling in Python Class 12

File Handling in Python Class 12 MCQ


Click here to check your performance in file handling in python class 12

File Handling in Python Class 12 MCQ

Q41. The syntax of seek() is:file_object.seek(offset [, reference_point] What is the default value of reference_point

a. 0

b. 1

c. 2

d. 3

Q42. _______ function returns the current position of file pointer.

a. get( )

b. tell( )

c. cur( )

d. seek( )

Q43. f.seek(10,0) will move 10 bytes forward from beginning of file.(T/F)

a. True

b. False

Q44. Which statement will move file pointer 10 bytes backward from current position.

a. f.seek(-10, 0)

b. f.seek(10, 0)

c. f.seek(-10, 1)

d. None of the above

Q45. When we open file in append mode the file pointer is at the _________ of the file.

a. end

b. beginning

c. anywhere in between the file

d. second line of the file

File Handling in Python Class 12 MCQ

Q46. When we open file in write mode the file pointer is at the _______ of the file.

a. end

b. beginning

c. anywhere in between the file

d. second line of the file

Q47. Write the output of the First Print statements :

f=open("data.txt",'w')
f.write("Hello")
f.write("Welcome to my Blog")
f.close()
f=open("data.txt",'r')
d=f.read(5)
print(d) # First Print Statement
f.seek(10)
d=f.read(3)
print(d) # Second Print Statement
f.seek(13)
d=f.read(5)
print(d) # Third Print Statement
d=f.tell()
print(d) # Fourth Print Statement

a. Hello

b. Hell

c. ello

d. None of the above

Q48. Refer to the above code (Q 47) : Write the output of Second Print Statement

a. om

b. me

c. co

d. None of the above

Q49. Refer to the above code (Q 47) : Write the output of Third Print Statement

a. e to m

b. e to my

c. to my

d. None of the above

Q50. Refer to the above code (Q 47) : Write the output of Fourth Print Statement

a. 17

b. 16

c. 19

d. 18

File Handling in Python Class 12 MCQ


Click here to check your performance in file handling in python class 12

File Handling in Python Class 12 MCQ

Q51. A _____________ is a named location on a secondary storage media where data are permanently stored for later access.

a. file

b. variable

c. comment

d. token

Q52. A _____ file consists of human readable characters.

a. Binary

b. Text

c. Both of the above

d. None of the above

Q53. Which of the following file require specific programs to access its contents?

a. Binary

b. Text

c. CSV

d. None of the above

Q54. Which of the following file can be opened in any text editor?

a. Binary

b. Text

c. Both of the above

d. None of the above

Q55. Each line of a text file is terminated by a special character, called the ________

a. End of File

b. End of Line

c. End of Statement

d. End of program

File Handling in Python Class 12 MCQ

Q56. Default EOL character in text file is ________

a. \n

b. \N

c. \t

d. \l

Q57. Which of the following file can be created in python?

a. Text File

b. Binary File

c. CSV File

d. All of the above

Q58. In which of the following data store permanently?

a. File

b. Variable

c. Both of the above

d. None of the above

Q59. open( ) function takes ____ as parameter.

a. File name

b. Access mode

c. Both of the above

d. None of the above

Q60. Identify the correct statement to open a file:

a. f = open(“D:\\myfolder\\naman.txt”)

b. f = open(“D:\myfolder\naman.txt”)

c. f = open(“D:myfolder#naman.txt”)

d. f = Open(“D:\myfolder\naman.txt”)

File Handling in Python Class 12
File Handling in Python Class 12

File Handling in Python Class 12 MCQ


Click here to check your performance in file handling in python class 12

File Handling in Python Class 12 MCQ

Q61. Which of the following are the attributes of file handle?

a. closed

b. name

c. mode

d. All of the above

Q62. Write the output of the following:

>>> f = open("test.txt","w")
>>> f.closed

a. True

b. False

c. Yes

d. No

Q63. Write the output of the following:

>>> f = open("test.txt","w")
>>> f.mode

a. ‘w’

b. ‘r’

c. ‘a’

d. ‘w+’

Q64. Write the output of the following:

>>> f = open("test.txt","w")
>>> f.name

a. ‘test’

b. ‘test.txt’

c. ‘test.dat’

d. file does not exist

Q65. Write the output of the following:

>>> f = open("test.txt","w")
>>> f.close()
>>> f.closed

a. True

b. False

c. Yes

d. No

File Handling in Python Class 12 MCQ

Q66. Which of the following attribute of file handle returns Boolean value?

a. name

b. closed

c. mode

d. None of the above

Q67. Ravi opened a file in python using open( ) function but forgot to specify the mode. In which mode the file will open?

a. write

b. append

c. read

d. read and write both

Q68. Which of the following is invalid mode of opening file?

a. r

b. rb

c. +r

d. None of the above

Q69. Which of the following mode will create a new file, if the file does not exist?

a. ‘a’

b. ‘a+’

c. ‘+a’

d. All of the above

Q70. Which of the following mode will open the file in binary and read-only mode.

a. ‘r’

b. ‘rb’

c. ‘r+’

d. ‘rb+’

File Handling in Python Class 12 MCQ


Click here to check your performance in file handling in python class 12

File Handling in Python Class 12 MCQ

Q71. Which of the following mode will opens the file in read, write and binary mode?

a. ‘wb+

b. ‘+wb’

c. Both of the above

d. None of the above

Q72. In the given statement, the file myfile.txt will open in _______________ mode.

myObject=open(“myfile.txt”, “a+”)

a. append and read

b. append and write

c. append and read and binary

d. All of the above

Q73. Ravi opened the file myfile.txt in append mode. In this file the file object/file handle will be at the __________

a. beginning of the file

b. end of the file

c. second line of the file

d. the end of the first line

Q74. Ravi opened the file myfile.txt in write mode. In this file the file object/file handle will be at the ______________

a. beginning of the file

b. end of the file

c. second line of the file

d. the end of the first line

Q75. Ravi opened the file myfile.txt in read mode. In this file the file object/file handle will be at the _______________

a. beginning of the file

b. end of the file

c. second line of the file

d. the end of the first line

File Handling in Python Class 12 MCQ

Q76. Ravi opened a file in a certain mode. After opening the file, he forgot the mode. One interesting fact about that mode is ” If the file already exists, all the contents will be overwritten”. Help him to identify the correct mode.

a. read mode

b. write mode

c. append mode

d. binary and read mode

Q77. Ram opened a file in a certain mode. After opening the file, he forgot the mode. The interesting facts about that mode are ” If the file doesn’t exist, then a new file will be created” and “After opening file in that mode the file handle will be at the end of the file” Help him to identify the correct mode.

a. read mode

b. write mode

c. append mode

d. binary and read mode

Q78. Which of the following function is used to close the file?

a. close( )

b. end( )

c. quit( )

d. exit( )

Q79. open( ) function returns a file object called ______________

a. object handle

b. file handle

c. read handle

d. write handle

Q80. Which of the following is the valid way to open the file?

a. with open (file_name, access_mode) as fo:

b. fo = open (file_name, access_mode)

c. Both of the above

d. None of the above

File Handling in Python Class 12 MCQ


Click here to check your performance in file handling in python class 12

File Handling in Python Class 12 MCQ

Q81. Rohan opened the file “myfile.txt” by using the following syntax. His friend told him few advantages of the given syntax. Help him to identify the correct advantage.

with open ("myfile.txt", "a") as file_object:

a. In case the user forgets to close the file explicitly the file will closed automatically.

b. file handle will always be present in the beginning of the file even in append mode.

c. File will be processed faster

d. None of the above

Q82. Mohan wants to open the file to add some more content in the already existing file. Suggest him the suitable mode to open the file.

a. read mode

b. append mode

c. write mode

d. All of the above

Q83. Aman jotted down few features of the “write mode”. Help him to identify the valid features.

a. If we open an already existing file in write mode, the previous data will be erased

b. In write mode, the file object will be positioned at the beginning of the file.

c. In write mode, if the file does not exist then the new file will be created.

d. All of the above

Q84. Ananya jotted down few features of the “append mode”. Help her to identify the valid features.

a. If we open an existing file in append mode, the previous data will remain there.

b. In append mode the file object will be positioned at the end of the file.

c. In append mode, if the file does not exist then the new file will be created.

d. All of the above

Q85. Which of the following methods can be used to write data in the file?

a. write( )

b. writelines( )

c. Both of the above

d. None of the above

File Handling in Python Class 12 MCQ

Q86. Write the output of the following:

>>> f = open("test.txt","w")
>>> f.write("File\n#Handling")

a. 17

b. 16

c. 14

d. 15

Q87. Which of the following error is returned by the given code:

>>> f = open("test.txt","w")
>>> f.write(345)

a. Syntax Error

b. TypeError

c. StringError

d. Run Time Error

Q88. Which of the following method is used to clear the buffer?

a. clear( )

b. buffer( )

c. flush( )

d. clean( )

Q89. Which of the following method does not return the number of characters written in the file.

a. write( )

b. writelines( )

c. Both of the above

d. None of the above

Q90. Fill in the blank in the given code:

>>> fo = open("myfile.txt",'w')
>>> lines = ["Hello \n", "Writing strings\n", "third line"]
>>> fo._____________(lines)
>>>myobject.close()

a. write( )

b. writelines( )

c. writeline( )

d. None of the above

File Handling in Python Class 12 MCQ


Click here to check your performance in file handling in python class 12

File Handling in Python Class 12 MCQ

Q91. In order to read the content from the file, we can open file in ___________________

a. “r” mode

b. “r+” mode

c. “w+” mode

d. All of the above

Q92. Which of the following method is used to read a specified number of bytes of data from a data file.

a. read( )

b. read(n)

c. readlines( )

d. reading(n)

Q93. Write the output of the following:

f=open("test.txt","w+")
f.write("File-Handling")
a=f.read(5)
print(a)

a. File-

b. File

c. File-H

d. No Output

Q94. Write the output of the following:

f=open("test.txt","w+")
f.write("File-Handling")
f.seek(0)

a=f.read(5)
print(a)

a. File-

b. File

c. File-H

d. No Output

Q95. Write the output of the following:

f=open("test.txt","w+")
f.write("FileHandling")
f.seek(5)

a=f.read(5)
print(a)

a. andli

b. Handl

c. eHand

d. No Output

File Handling in Python Class 12 MCQ

Q96. Write the output of the following:

f=open("test.txt","w+")
f.write("FileHandling")
f.seek(0)

a=f.read()
print(a)

a. File

b. Handling

c. FileHandling

d. No Output

Q97. Write the output of the following:

f=open("test.txt","w+")
f.write("FileHandling")
f.seek(0)

a=f.read(-1)
print(a)

a. File

b. Handling

c. FileHandling

d. No Output

Q98. Which of the following method reads one complete line from a file?

a. read( )

b. read(n)

c. readline( )

d. readlines( )

Q99. Write the output of the following:

f=open("test.txt","w+")
f.write("File\nHandling")
f.seek(0)
a=f.readline(-1)
print(a)

a. File Handling

b. FileHandling

c. File

d. No Output

Q100. Write the output of the following:

f=open("test.txt","w+")
f.write("File\nHandling")
f.seek(0)
a=f.readline(2)
print(a)

a. File\nHandling

b. FileHandling

c. Fi

d. No Output

File Handling in Python Class 12 MCQ


Click here to check your performance in file handling in python class 12

File Handling in Python Class 12 MCQ

Q101. Select the correct statement about the code given below:

>>> myobj=open("myfile.txt", 'r')
>>> print(myobj.readlines())

a. This code will read one line from the file.

b. This code will read all the lines from the file.

c. This code will read only last line from the file.

d. None of the above

Q102. Write the output of the following:

f=open("test.txt","w+")
L = ["My name\n", "is\n", "Amit"]
f.writelines(L)
f.seek(0)
a=f.readlines()
print(type(a))

a. <class ‘tuple’>

b. <class ‘list’>

c. <class ‘string’>

d. None of the above

Q103. Which of the following function return the data of the file in the form of list?

a. read( )

b. read(n)

c. readline( )

d. readlines( )

Q104. Sanjeev has written a program which is showing an error. As a friend of Sanjeev, help him to identify the wrong statement.

f=open("test.txt","w") #Statement1
L = ["My name\n", "is\n", "Amit"] #Statement2
f.writeline(L) #Statement3
f.close() #Statement4

a. Statement1

b. Statement2

c. Statement3

d. Statement4

Q105. ____________________ function returns an integer that specifies the current position of the file object in the file.

a. seek( )

b. tell( )

c. disp( )

d. None of the above

File Handling in Python Class 12 MCQ

Q106. _______ method is used to position the file object at a particular position in a file.

a. tell( )

b. seek( )

c. put( )

d. None of the above

Q107. In reference to the code given below, the file object will move _______ bytes.

file_object.seek(10, 0)

a. 0

b. 10

c. 5

d. 4

Q108. Ravi wants to move the file object 5 bytes from the current position of the file object. As a friend of Ravi, help him to write the code.

a. file_object.seek(5, 1)

b. file_object.seek(1, 5)

c. file_object.seek(5, 0)

d. file_object.seek(5, 2)

Q109. Write the output of the following code:

f=open("test.txt","w+")
f.write("My name is Amit\n")
f.seek(5,0)
a=f.read(5)
print(a)

a. me i

b. ame is

c. me is

d. Error

File Handling in Python Class 12 MCQ


Click here to check your performance in file handling in python class 12

File Handling in Python Class 12 MCQ

Q111. Write the output of the following:

f=open("test.txt","r")
print(f.tell())

a. 1

b. 2

c. -1

d. 0

Q112. Write the output of the following:

f=open("test.txt","r")
print(f.tell(),end="6")
f.seek(5)
print(f.tell())

a. 165

b. 650

c. 065

d. 506

Q113. How many functions are used in the given code?

fileobject=open("practice.txt","r")
str = fileobject.readline()
while str:
     print(str)
     str=fileobject.readline()
fileobject.close()

a. 3

b. 4

c. 5

d. 6

Q114. _________ method is used to write the objects in a binary file.

a. write( )

b. dump( )

c. load( )

d. writer( )

Q115. _________ method is used to read data from a binary file.

a. write( )

b. dump( )

c. load( )

d. writer( )

File Handling in Python Class 12 MCQ

Q116. Which module is to be imported for working in binary file?

a. unpickle

b. pickle

c. pickling

d. unpickling

Q117. Which of the following statement open the file “marker.txt” so that we can read existing content from file?

a. f = open(“marker.txt”, “r”)

b. f = Open(“marker.txt”, “r”)

c. f = open(“marker.txt”, “w”)

d. None of the above

Q118. Which of the following statement open the file “marker.txt” as a blank file?

a. f = open(“marker.txt”, “r”)

b. f = open(“marker.txt”, “rb”)

c. f = open(“marker.txt”, “w”)

d. None of the above

Q119. Amit has written the following statement. He is working with ______

f = open("data", "rb")

a. Text File

b. CSV File

c. Binary File

d. None of the above

Q120. Which of the following option is correct?

a. if we try to write in 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, the file gets Created.

d. None of the value

File Handling in Python Class 12 MCQ


Click here to check your performance in file handling in python class 12

Q121. Correct syntax of tell( ) function is _________. #f is file object

a. f.tell( )

b. tell(f)

c. f_tell( )

d. None of the above

Q122. The syntax of seek() is: file_object.seek(offset [, reference_point]). ___________________ value of reference_point indicate end of file

a. 0

b. 1

c. 2

d. 3

Q123. Which of the following statement is wrong in reference to Text file?

a. A text file is usually considered as a sequence of characters consisting of alphabets, numbers and other special symbols.

b. Each line of a text file is terminated by a special character.

c. Text files are not in Human readable form.

d. Text files can be opened in Text editor.

Q124. Identify the statement which can not be interpret from the given code:

f = open("test.dat", "ab+")

a. test.dat is a binary file

b. reading operation can be done on test.dat

c. appending operation can be done on test.dat

d. test.dat contains records about books

Q125. Which module is to be imported for CSV file?

a. pickle

b. unpickle

c. csv

d. pandas

File Handling in Python Class 12 MCQ

Q126. Write the output of the following code :

import csv
f = open(“data.csv”, ‘r’)
row = csv.reader(f)
print(row) 
 

a. It prints the memory address where csv.reader object is stored

b. It prints the first record of data.csv

c. It prints all the records of data.csv

d. None of the above

Q127. _________ function help us to read the csv file.

a. reader( )

b. read( )

c. read(n)

d. readline( )

Q128. Write the output of the second print statement of the given code:

f=open("test.txt","r")
print(f.read())
f.seek(7)
print(f.read())

Output of first print statement is : MynameisAmit

a. isAmit

b. sAmit

c. Amit

d. eisAmit

Q129. Which of the following method returns an integer value?

a. seek( )

b. read( )

c. tell( )

d. readline( )

Q130. ___________ refers to the process of converting the structure to a byte stream before writing it to the file.

a. pickling

b. unpickling

c. reading

d. writing

File Handling in Python Class 12 MCQ


Click here to check your performance in file handling in python class 12

File Handling in Python Class 12 MCQ

Q131. Fill in the blank in the given code :

import pickle
f = open("data.dat", "rb")
l = pickle._______(f)
print(l)
f.close()

a. dump

b. load

c. write

d. list

Q132. Write the output of the following code:

f = open("data.txt","w")
L=["My\n","name\n","is\n","amit"]
f.writelines(L)
f.close()
f = open("data.txt","r")
print(len(f.read()))

a. 13

b. 14

c. 15

d. 16

Q133. Write the output of the following code:

f = open("data.txt","w")
L=["My\n","name\n","is\n","amit"]
f.writelines(L)
f.close()
f = open("data.txt","r")
print(len(f.readlines()))

a. 4

b. 5

c. 6

d. 7

Q134. Write the output of the following code:

f = open("data.txt","w")
L=["My\n","name\n","is\n","amit"]
f.writelines(L)
f.close()
f = open("data.txt","r")
print(len(f.readline()))

a. 2

b. 3

c. 4

d. 5

Q135. Fill in the blank in the given code :

import pickle
f = open("data.dat", "wb")
L = [1, 2, 3]

pickle._______
f.close()

a. dump(f, L)

b. load(f, L)

c. dump(L, f)

d. load(L, f)

File Handling in Python Class 12 MCQ

Q136. Which of the following statement will return attribute error?

a. print(len(f.readlines( ).split( ))) #f is file handle

b. print(len(f.readline( ).split( ))) #f is file handle

c. print(len(f.read( ).split( ))) #f is file handle

d. None of the above

Q137. Ravi is writing a program for counting the number of words in a text file named “data.txt”. He has written the incomplete code. Help him to complete the code.

f = open("_________","r") # Statement 1
d = f._________ # Statement 2
nw = d._________ # Statement 3
print("Number of words are", _________(nw)) # Statement 4

Identify the suitable code for blank space in the line marked as Statement 1

a. “data.txt”

b. data.txt

c. “data”

d. data

Q138. Identify the suitable code for blank space in the line marked as Statement 2(Refer Q. 137)

a. readlines( )

b. readline( )

c. read( )

d. None of the above

Q139. Identify the suitable code for blank space in the line marked as Statement 3(Refer Q. 137)

a. split( )

b. break( )

c. words( )

d. jump( )

Q140. Identify the suitable code for blank space in the line marked as Statement 4(Refer Q. 137)

a. length

b. len

c. Len

d. Length

File Handling in Python Class 12 MCQ


Click here to check your performance in file handling in python class 12

File Handling in Python Class 12 MCQ

Q141. Ananya was writing a program of reading data from csv file named “data.csv”. She writes the incomplete code. As a friend of Ananya help her to complete the code.

________ csv  #Statement1
f=open("data.csv", '_______')  #Statement2
d=csv.___________(f)  #Statement3
for __________ in d:  #Statement4
     print(row)

Identify the suitable option for Statement 1

a. import

b. create

c. data

d. Import

Q142. Identify the correct option for Statement2 (Refer Q 141)

a. w

b. a

c. rb

d. r

Q143. Identify the correct option for Statement3 (Refer Q 141)

a. readlines

b. readline

c. read

d. reader

Q144. Identify the correct option for Statement4 (Refer Q 141)

a. row

b. d

c. csv

d. i

Q145. Parth is writing a program to add/insert records in file “data.csv”. He has written the following code. As a programmer, help him to execute it successfully.

import csv
field = [“Roll no” , “Name” , “Class”]

f = open(“_________” , ‘w’)            #Statement1
d=__________.writer(f)               #Statement2
d.writerow(field)

ch=’y’

while ch==’y’ or ch==’Y’:

        rn=int(input(“Enter Roll number: “))

        nm = input(“Enter name: “)

        cls = input(“Enter Class: “)

        rec=[_________]          #Statement3
        d.writerow(rec)

        ch=input(“Enter more record??(Y/N)”)

f.close()

Identify the correct statement for Statement 1

a. data

b. data.csv

c. file_data.csv

d. None of the above

File Handling in Python Class 12 MCQ

Q146. Identify the correct statement for Statement 2. (Refer Q. 145)

a. CSV

b. csv

c. file

d. csv_

Q147. Identify the correct statement for Statement 3. (Refer Q. 145)

a. rollno, name, class

b. Roll no, Name, Class

c. rn, nm, cls

d. field

Q148. Chinki is writing a program to copy the data from “data.csv” to “temp.csv”. However she is getting some error in executing the following program due to some missing commands. Help her to execute it successfully.

import csv
f=open(“data.csv”,”r”)

f1=open(“temp.csv”,’__________’)        #Statement 1
d=csv._________(f)         #Statement 2
d1=csv.writer(f1)

for i in d:

        ___________.writerow(i)              #Statement3
f.close( )
f1.close( )

Identify the correct statement for Statement 1.

a. r

b. rb+

c. wa

d. w

Q149. Identify the correct statement for Statement 2.(Refer Q148.)

a. read

b. reader( )

c. reader

d. read(r)

Q150. Identify the correct statement for Statement 2.(Refer Q148.)

a. d

b. d1

c. f

d. f1

File Handling in Python Class 12 MCQ


Click here to check your performance in file handling in python class 12

Q151. Simran is writing a function by name “bookshop” in which she is asking about book name and price from the user and storing the details in a file “book.txt”. Function is showing some error due to some missing words/commands. As a programmer help her to write the correct program.

_________________ bookshop:    #Statement 1
    b_name = input("Enter book name:") 
    b_price=int(input("Enter book price:")) 
    data = _________________([b_name, b_price])  #Statement 2
    f = open("book.txt","w") 
    f.write(_____________) #Statement 3
f.close()

Identify the correct option for Statement 1.

a. def

b. Def

c. define

d. Define

Q152. Identify the correct option for Statement 2.

a. int

b. str

c. char

d. float

Q153. Identify the correct option for Statement 3.

a. data

b. b_name

c. b_price

d. f

File Handling in Python Class 12 MCQ

Disclaimer : I tried to give you the correct solution of “ File Handling in Python Class 12 MCQ , but if you feel that there is/are mistakes in “ File Handling in Python Class 12 MCQ ” given above, you can directly contact me at csiplearninghub@gmail.com. NCERT Book and Study material available on CBSE official website are used as a reference to create above “ File Handling in Python Class 12 MCQ

File Handling in Python Class 12 MCQ

Important Links

100 Practice Questions on Python Fundamentals

120+ MySQL Practice Questions

90+ Practice Questions on List

50+ Output based Practice Questions

100 Practice Questions on String

70 Practice Questions on Loops

120 Practice Questions of Computer Network in Python

70 Practice Questions on if-else

40 Practice Questions on Data Structure

Computer Science Syllabus 2021-2022.

Informatics Practices Syllabus 2021-2022

Class 12 Computer Science Chapter wise MCQ

File Handling in Python Class 12 MCQ


Share with others

1 thought on “150+ Best MCQ File Handling in Python Class 12”

  1. only one issue we cannot able to download the content in this site.
    And with this MCQs we can able to complete the hole lessons easily best for the beginners.

    Reply

Leave a Reply

error: Content is protected !!