You are on page 1of 16

Q1. Which statement will read 5 characters d.

End or File
from a file(file object ‘f’)?
a. f.read() Ans. a. End of File
b. f.read(5) Q8. Which function is used to read data from
c. f.reads(5) Text File?
d. None of the above a. read( )
b. writelines( )
Ans. b. f.read(5) c. pickle( )
Q2. Which function open file in python? d. dump( )
a. open( )
b. new( ) Ans. a. read( )
c. Open( ) Q9. Which of the following will read entire
d. None of the above content of file(file object ‘f’)?
a. f.reads( )
Ans. a. open( ) b. f.read( )
Q3. Processing of Text file is faster than c. f.read(all)
binary files.(T/F) d. f.read( * )
a. True
b. False Ans. b. f.read( )
Q10. Which symbol is used for append
Ans. b. False mode?
Q4. Which mode create new file if the file a. ap
does not exist? b. a
a. write mode c. w
b. append mode d. app
c. Both of the above
d. None of the above Ans. b. a

Ans. c. Both of the above Q11. Which of the following options can be
Q5. Which statement will return one line used to read the first line of a text file
from a file (file object is ‘f’)? data.txt?
a. f.readline( ) a. f = open(‘data.txt’); f.read()
b. f.readlines( ) b. f = open(‘data.txt’,’r’); f.read(n)
c. f.read( ) c. myfile = open(‘data.txt’); f.readline()
d. f.line( ) d. f = open(‘data.txt’); f.readlines()

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


f.readline()
Q6. readlines() method return _________ Q12. File in python is treated as sequence of
a. String ________________
b. List a. Bytes
c. Dictionary b. Bites
d. Tuple c. bits
d. None of the above
Ans. b. List
Q7. EOF stands for _________________ Ans. a. Bytes
a. End of File Q13. Which function is used to write data in
b. End off File binary mode?
c. End on File a. write
b. writelines Ans. c. Both of the above
c. pickle Q19. The syntax of seek() is:
d. dump file_object.seek(offset [, reference_point])
What is reference_point indicate?
Ans. d. dump a. reference_point indicates the
Q14. Which function is used to force transfer starting position of the file object
of data from buffer to file? b. reference_point indicates the ending
a. flush( ) position of the file object
b. save( ) c. reference_point indicates the current
c. move( ) position of the file object
d. None of the above d. None of the above.

Ans. a. flush( ) Ans. a. reference_point indicates the


Q15. Let the file pointer is at the end of 3rd starting position of the file object
line in a text file named “data.txt”. Which of Q20. Identify the invalid mode from the
the following option can be used to read all following.
the remaining lines? a. a
a. f.read( ) b. r+
b. f.read(all) c. ar+
c. f.readline( ) d. w
d. f.readlines( )
Ans. c. ar+
Ans. d. f.readlines( )
Q21. Which of the following is an invalid
Q16. ____________________ module is mode of file opening?
used for serializing and de-serializing any a. read only mode
Python object structure. b. write only mode
a. pickle c. read and write mode
b. unpickle d. write and append mode
c. pandas
d. math Ans. d. write and append mode
Q22. readlines( ) function returns all the
Ans. a. pickle words of the file in the form of List. (T/F)
Q17. Which of the following error is returned a. True
when we try to open a file in write mode b. False
which does not exist?
a. FileNotFoundError Ans. b. False
b. FileFoundError Q23. What is ‘f’ in the following statement?
c. FileNotExistError f=open("Data.txt" , "r")
d. None of the above a. File Name
b. File Handle
Ans. d. None of the above r c. Mode of file
Q18. ______________ function returns the d. File Handling
strings.
a. read( ) Ans. b. File Handle
b. readline( ) Q24. What is full form of CSV
c. Both of the above a. Comma Separation Value
d. None of the above b. Comma Separated Value
c. Common Syntax Value
d. Comma Separated Variable b. Statement 2
c. Statement 3
Ans. b. Comma Separated Value d. Statement 4
Q25. Which statement will open file
“data.txt” in append mode? Ans. d. Statement 4
a. f = open(“data.txt” , “a”) Q30. Which of the following function takes
b. f = Open(“data.txt” , “ab”) two arguments?
c. f = new(“data.txt” , “a”) a. load( )
d. open(“data.txt” , “a”) b. dump( )
c. both of the above
Ans. a. f = open(“data.txt” , “a”) d. none of the above

Q26. Fill in the blank Ans. b. dump( )

Q31. Almost all the files in our computer


import pickle stored as _______ File.
f=open("data.dat",'rb') a. Text
d=_____________________.load(f) b. Binary
f.close() c. CSV
a. unpickle d. None of the above
b. pickling
c. pickle Ans. b. Binary
d. pick Q32. Binary files are not in human readable
format.(T/F)
Ans. c. pickle a. True
Q27. Which module to be imported to make b. False
the following line functional?
sys.stdout.write("ABC") Ans. a. True
a. system Q33. .pdf and .doc are examples of
b. sys __________ files.
c. stdout a. Text
d. stdin b. Binary
c. CSV
Ans. b. sys d. None of the above
Q28. What error is returned by the following
statement if the file does not exist? Ans. b. Binary
f=open("A.txt") Q34. The syntax of seek()
a. FileNotFoundError is:file_object.seek(offset [, reference_point])
b. NotFoundError What all values can be given as a reference
c. FileNotFound point?
d. FoundError a. 1
b. 2
Ans. a. FileNotFoundError c. 0
Q29. Which statement will return error? d. All of the above
import pickle
f=open("data.dat",'rb') Ans. d. All of the above
d=pickle.load(f) Q35. There is no delimiter to end a line in
f.end() binary files.(T/F)
a. Statement 1 a. True
b. False
Ans. c. pickle
Ans. a. True Q40. Refer to the above code (Q 38)and
choose the option for statement 4.
Q36. seek( ) method is used for random a. f
access to the file.(T/F) b. rec
a. True c. file
b. False d. stud

Ans. a. True Ans. a. f


Q37. Fill in the blanks in the following code
of writing data in binary files. Choose the Q41. The syntax of seek()
answer for statement 1 is:file_object.seek(offset [, reference_point]
import ___________ # Statement 1 What is the default value of reference_point
rec = [ ] a. 0
while True: b. 1
rn = int(input("Enter")) c. 2
nm = input("Enter") d. 3
temp = [rn, nm]
rec.append(temp) Ans. a. 0
ch = input("Enter choice (Y/N)") Q42. _______ function returns the current
if ch.upper == "N": position of file pointer.
break a. get( )
f = open("stud.dat", "____________") b. tell( )
#statement 2 c. cur( )
__________ .dump(rec, f) d. seek( )
#statement 3
_______.close( ) # statement 4 Ans. b. tell( )
Q43. f.seek(10,0) will move 10 bytes forward
a. csv from beginning of file.(T/F)
b. unpickle a. True
c. pickle b. False
d. load
Ans. a. True
Ans. c. pickle Q44. Which statement will move file pointer
Q38. Refer to the above code and choose 10 bytes backward from current position.
the option for statement2. a. f.seek(-10, 0)
a. w b. f.seek(10, 0)
b. w+ c. f.seek(-10, 1)
c. wb d. None of the above
d. write
Ans. c. f.seek(-10, 1)
Ans. c. wb Q45. When we open file in append mode the
Q39. Refer to the above code (Q 38)and file pointer is at the _________ of the file.
choose the option for statement 3 a. end
a. unpickle b. beginning
b. write c. anywhere in between the file
c. pickle d. second line of the file
d. None of the above
Ans. a. end Q50. Refer to the above code (Q 47) : Write
the output of Fourth Print Statement
Q46. When we open file in write mode the a. 17
file pointer is at the _______ of the file. b. 16
a. end c. 19
b. beginning d. 18
c. anywhere in between the file
d. second line of the file Ans. d. 18

Ans. b. beginning Q51. A _____________ is a named location


Q47. Write the output of the First Print on a secondary storage media where data
statements : are permanently stored for later access.
f=open("data.txt",'w') a. file
f.write("Hello") b. variable
f.write("Welcome to my Blog") c. comment
f.close() d. token
f=open("data.txt",'r')
d=f.read(5) Ans. a. file
print(d) # First Print Statement Q52. A _____ file consists of human
f.seek(10) readable characters.
d=f.read(3) a. Binary
print(d) # Second Print Statement b. Text
f.seek(13) c. Both of the above
d=f.read(5) d. None of the above
print(d) # Third Print Statement
d=f.tell() Ans. b. Text
print(d) # Fourth Print Statement Q53. Which of the following file require
a. Hello specific programs to access its contents?
b. Hell a. Binary
c. ello b. Text
d. None of the above c. CSV
d. None of the above
Ans. a. Hello
Q48. Refer to the above code (Q 47) : Write Ans. a. Binary
the output of Second Print Statement Q54. Which of the following file can be
a. om opened in any text editor?
b. me a. Binary
c. co b. Text
d. None of the above c. Both of the above
d. None of the above
Ans. b. me
Q49. Refer to the above code (Q 47) : Write Ans. b. Text
the output of Third Print Statement Q55. Each line of a text file is terminated by
a. e to m a special character, called the ________
b. e to my a. End of File
c. to my b. End of Line
d. None of the above c. End of Statement
d. End of program
Ans. c. to my
Ans. b. End of Line b. name
c. mode
Q56. Default EOL character in text file is d. All of the above
________
a. \n Ans. d. All of the above
b. \N Q62. Write the output of the following:
c. \t >>> f = open("test.txt","w")
d. \l >>> f.closed
Answer a. True
a. \n b. False
c. Yes
Q57. Which of the following file can be d. No
created in python?
a. Text File Ans. b. False
b. Binary File Q63. Write the output of the following:
c. CSV File >>> f = open("test.txt","w")
d. All of the above >>> f.mode
a. ‘w’
Ans. d. All of the above b. ‘r’
Q58. In which of the following data store c. ‘a’
permanently? d. ‘w+’
a. File
b. Variable Ans. a. ‘w’
c. Both of the above Q64. Write the output of the following:
d. None of the above >>> f = open("test.txt","w")
>>> f.name
Ans. a. File a. ‘test’
Q59. open( ) function takes ____ as b. ‘test.txt’
parameter. c. ‘test.dat’
a. File name d. file does not exist
b. Access mode
c. Both of the above Ans. b. ‘test.txt’
d. None of the above Q65. Write the output of the following:
>>> f = open("test.txt","w")
Ans. c. Both of the above >>> f.close()
Q60. Identify the correct statement to open >>> f.closed
a file: a. True
a. f = open(“D:\\myfolder\\ b. False
naman.txt”) c. Yes
b. f = open(“D:\myfolder\naman.txt”) d. No
c. f = open(“D:myfolder#naman.txt”)
d. f = Open(“D:\myfolder\naman.txt”) Ans. a. True

Ans. a. f = open(“D:\\myfolder\\ Q66. Which of the following attribute of file


naman.txt”) handle returns Boolean value?
a. name
Q61. Which of the following are the b. closed
attributes of file handle? c. mode
a. closed d. None of the above
b. append and write
Ans. b. closed c. append and read and binary
Q67. Ravi opened a file in python using d. All of the above
open( ) function but forgot to specify the
mode. In which mode the file will open? Ans. a. append and read
a. write Q73. Ravi opened the file myfile.txt in
b. append append mode. In this file the file object/file
c. read handle will be at the __________
d. read and write both a. beginning of the file
b. end of the file
Ans. c. read c. second line of the file
Q68. Which of the following is invalid mode d. the end of the first line
of opening file?
a. r Ans. b. end of the file
b. rb Q74. Ravi opened the file myfile.txt in write
c. +r mode. In this file the file object/file handle
d. None of the above will be at the ______________
a. beginning of the file
Ans. d. None of the above b. end of the file
Q69. Which of the following mode will create c. second line of the file
a new file, if the file does not exist? d. the end of the first line
a. ‘a’
b. ‘a+’ Ans. a. beginning of the file
c. ‘+a’ Q75. Ravi opened the file myfile.txt in read
d. All of the above mode. In this file the file object/file handle
will be at the _______________
Ans. d. All of the above a. beginning of the file
Q70. Which of the following mode will open b. end of the file
the file in binary and read-only mode. c. second line of the file
a. ‘r’ d. the end of the first line
b. ‘rb’
c. ‘r+’ Ans. a. beginning of the file
d. ‘rb+’
Q76. Ravi opened a file in a certain mode.
Ans. b. ‘rb’ After opening the file, he forgot the mode.
One interesting fact about that mode is ” If
Q71. Which of the following mode will opens the file already exists, all the contents will be
the file in read, write and binary mode? overwritten”. Help him to identify the correct
a. ‘wb+ mode.
b. ‘+wb’ a. read mode
c. Both of the above b. write mode
d. None of the above c. append mode
d. binary and read mode
Ans. c. Both of the above
Q72. In the given statement, the file Ans. b. write mode
myfile.txt will open in _______________ Q77. Ram opened a file in a certain mode.
mode. After opening the file, he forgot the mode.
myObject=open(“myfile.txt”, “a+”) The interesting facts about that mode are ”
a. append and read If the file doesn’t exist, then a new file will
be created” and “After opening file in that d. None of the above
mode the file handle will be at the end of the
file” Help him to identify the correct mode. Ans. a. In case the user forgets to close
a. read mode the file explicitly the file will closed
b. write mode automatically.
c. append mode Q82. Mohan wants to open the file to add
d. binary and read mode some more content in the already existing
file. Suggest him the suitable mode to open
Ans. c. append mode the file.
Q78. Which of the following function is used a. read mode
to close the file? b. append mode
a. close( ) c. write mode
b. end( ) d. All of the above
c. quit( )
d. exit( ) Ans. b. append mode
Q83. Aman jotted down few features of the
Ans. a. close( ) “write mode”. Help him to identify the valid
Q79. open( ) function returns a file object features.
called ______________ a. If we open an already existing file in
a. object handle write mode, the previous data will be
b. file handle erased
c. read handle b. In write mode, the file object will be
d. write handle positioned at the beginning of the file.
c. In write mode, if the file does not
Ans. b. file handle exist then the new file will be created.
Q80. Which of the following is the valid way d. All of the above
to open the file?
a. with open (file_name, access_mode) Ans. d. All of the above
as fo: Q84. Ananya jotted down few features of the
b. fo = open (file_name, access_mode) “append mode”. Help her to identify the valid
c. Both of the above features.
d. None of the above a. If we open an existing file in append
mode, the previous data will remain
Ans. c. Both of the above there.
b. In append mode the file object will
be positioned at the end of the file.
Q81. Rohan opened the file “myfile.txt” by c. In append mode, if the file does not
using the following syntax. His friend told exist then the new file will be created.
him few advantages of the given syntax. d. All of the above
Help him to identify the correct advantage.
with open ("myfile.txt", "a") as Ans. d. All of the above
file_object: Q85. Which of the following methods can be
a. In case the user forgets to close the used to write data in the file?
file explicitly the file will closed a. write( )
automatically. b. writelines( )
b. file handle will always be present in c. Both of the above
the beginning of the file even in append d. None of the above
mode.
c. File will be processed faster Ans. c. Both of the above
Q86. Write the output of the following: Q91. In order to read the content from the
>>> f = open("test.txt","w") file, we can open file in
>>> f.write("File\n#Handling") ___________________
a. 17 a. “r” mode
b. 16 b. “r+” mode
c. 14 c. “w+” mode
d. 15 d. All of the above

Ans. c. 14 Ans. d. All of the above


Q87. Which of the following error is returned Q92. Which of the following method is used
by the given code: to read a specified number of bytes of data
>>> f = open("test.txt","w") from a data file.
>>> f.write(345) a. read( )
a. Syntax Error b. read(n)
b. TypeError c. readlines( )
c. StringError d. reading(n)
d. Run Time Error
Ans. b. read(n)
Ans. b. TypeError Q93. Write the output of the following:
Q88. Which of the following method is used f=open("test.txt","w+")
to clear the buffer? f.write("File-Handling")
a. clear( ) a=f.read(5)
b. buffer( ) print(a)
c. flush( ) a. File-
d. clean( ) b. File
c. File-H
Ans. c. flush( ) d. No Output
Q89. Which of the following method does not
return the number of characters written in Ans. d. No Output
the file. Q94. Write the output of the following:
a. write( ) f=open("test.txt","w+")
b. writelines( ) f.write("File-Handling")
c. Both of the above f.seek(0)
d. None of the above a=f.read(5)
print(a)
Ans. b. writelines( ) a. File-
Q90. Fill in the blank in the given code: b. File
>>> fo = open("myfile.txt",'w') c. File-H
>>> lines = ["Hello \n", "Writing d. No Output
strings\n", "third line"]
>>> fo._____________(lines) Ans. a. File-
>>>myobject.close() Q95. Write the output of the following:
a. write( ) f=open("test.txt","w+")
b. writelines( ) f.write("FileHandling")
c. writeline( ) f.seek(5)
d. None of the above a=f.read(5)
print(a)
Ans. b. writelines( ) a. andli
b. Handl Ans. c. File
c. eHand Q100. Write the output of the following:
d. No Output f=open("test.txt","w+")
f.write("File\nHandling")
Ans. a. andli f.seek(0)
a=f.readline(2)
Q96. Write the output of the following: print(a)
f=open("test.txt","w+") a. File\nHandling
f.write("FileHandling") b. FileHandling
f.seek(0) c. Fi
a=f.read() d. No Output
print(a)
a. File Ans. c. Fi
b. Handling
c. FileHandling
d. No Output Q101. Select the correct statement about the
code given below:
Ans. c. FileHandling >>> myobj=open("myfile.txt", 'r')
Q97. Write the output of the following: >>> print(myobj.readlines())
f=open("test.txt","w+") a. This code will read one line from the
f.write("FileHandling") file.
f.seek(0) b. This code will read all the lines from
a=f.read(-1) the file.
print(a) c. This code will read only last line from
a. File the file.
b. Handling d. None of the above
c. FileHandling
d. No Output Ans. b. This code will read all the lines
from the file.
Ans. c. FileHandling Q102. Write the output of the following:
Q98. Which of the following method reads f=open("test.txt","w+")
one complete line from a file? L = ["My name\n", "is\n", "Amit"]
a. read( ) f.writelines(L)
b. read(n) f.seek(0)
c. readline( ) a=f.readlines()
d. readlines( ) print(type(a))
a. <class ‘tuple’>
Ans. c. readline( ) b. <class ‘list’>
Q99. Write the output of the following: c. <class ‘string’>
f=open("test.txt","w+") d. None of the above
f.write("File\nHandling")
f.seek(0) Ans. b. <class ‘list’>
a=f.readline(-1) Q103. Which of the following function return
print(a) the data of the file in the form of list?
a. File Handling a. read( )
b. FileHandling b. read(n)
c. File c. readline( )
d. No Output d. readlines( )
Ans. d. readlines( ) c. file_object.seek(5, 0)
Q104. Sanjeev has written a program which d. file_object.seek(5, 2)
is showing an error. As a friend of Sanjeev,
help him to identify the wrong statement. Ans. a. file_object.seek(5, 1)
f=open("test.txt","w") #Statement1 Q109. Write the output of the following
L = ["My name\n", "is\n", "Amit"] code:
#Statement2 f=open("test.txt","w+")
f.writeline(L) #Statement3 f.write("My name is Amit\n")
f.close() #Statement4 f.seek(5,0)
a. Statement1 a=f.read(5)
b. Statement2 print(a)
c. Statement3 a. me i
d. Statement4 b. ame is
c. me is
Ans. c. Statement3 d. Error
Q105. ____________________ function
returns an integer that specifies the current Ans. c. me is
position of the file object in the file.
a. seek( ) Q111. Write the output of the following:
b. tell( ) f=open("test.txt","r")
c. disp( ) print(f.tell())
d. None of the above a. 1
b. 2
Ans. b. tell( ) c. -1
d. 0
Q106. _______ method is used to position
the file object at a particular position in a Ans. d. 0
file. Q112. Write the output of the following:
a. tell( ) f=open("test.txt","r")
b. seek( ) print(f.tell(),end="6")
c. put( ) f.seek(5)
d. None of the above print(f.tell())
a. 165
Ans. b. seek( ) b. 650
Q107. In reference to the code given below, c. 065
the file object will move _______ bytes. d. 506
file_object.seek(10, 0)
a. 0 Ans. c. 065
b. 10 Q113. How many functions are used in the
c. 5 given code?
d. 4 fileobject=open("practice.txt","r")
str = fileobject.readline()
Ans. b. 10 while str:
Q108. Ravi wants to move the file object 5 print(str)
bytes from the current position of the file str=fileobject.readline()
object. As a friend of Ravi, help him to write fileobject.close()
the code. a. 3
a. file_object.seek(5, 1) b. 4
b. file_object.seek(1, 5) c. 5
d. 6 b. CSV File
c. Binary File
Ans. c. 5 d. None of the above
Q114. _________ method is used to write
the objects in a binary file. Ans. c. Binary File
a. write( ) Q120. Which of the following option is
b. dump( ) correct?
c. load( ) a. if we try to write in a text file that
d. writer( ) does not exist, an error occurs
b. if we try to read a text file that does
Ans. b. dump( ) not exist, the file gets created.
Q115. _________ method is used to read c. if we try to write on a text file that
data from a binary file. does not exist, the file gets Created.
a. write( ) d. None of the value
b. dump( )
c. load( ) Ans. c. if we try to write on a text file
d. writer( ) that does not exist, the file gets
Created.
Ans. c. load( )
Q121. Correct syntax of tell( ) function is
Q116. Which module is to be imported for _________. #f is file object
working in binary file? a. f.tell( )
a. unpickle b. tell(f)
b. pickle c. f_tell( )
c. pickling d. None of the above
d. unpickling
Ans. a. f.tell( )
Ans. b. pickle Q122. The syntax of seek() is:
Q117. Which of the following statement open file_object.seek(offset [, reference_point]).
the file “marker.txt” so that we can read ___________________ value of
existing content from file? reference_point indicate end of file
a. f = open(“marker.txt”, “r”) a. 0
b. f = Open(“marker.txt”, “r”) b. 1
c. f = open(“marker.txt”, “w”) c. 2
d. None of the above d. 3

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


Q118. Which of the following statement open Q123. Which of the following statement is
the file “marker.txt” as a blank file? wrong in reference to Text file?
a. f = open(“marker.txt”, “r”) a. A text file is usually considered as a
b. f = open(“marker.txt”, “rb”) sequence of characters consisting of
c. f = open(“marker.txt”, “w”) alphabets, numbers and other special
d. None of the above symbols.
b. Each line of a text file is terminated
Ans. c. f = open(“marker.txt”, “w”) by a special character.
Q119. Amit has written the following c. Text files are not in Human readable
statement. He is working with ______ form.
f = open("data", "rb") d. Text files can be opened in Text
a. Text File editor.
f=open("test.txt","r")
Ans. c. Text files are not in Human print(f.read())
readable form. f.seek(7)
Q124. Identify the statement which can not print(f.read())
be interpret from the given code:
f = open("test.dat", "ab+") Output of first print statement is :
a. test.dat is a binary file MynameisAmit
b. reading operation can be done on a. isAmit
test.dat b. sAmit
c. appending operation can be done on c. Amit
test.dat d. eisAmit
d. test.dat contains records about
books Ans. b. sAmit
Q129. Which of the following method returns
Ans. d. test.dat contains records about an integer value?
books a. seek( )
Q125. Which module is to be imported for b. read( )
CSV file? c. tell( )
a. pickle d. readline( )
b. unpickle
c. csv Ans. c. tell( )
d. pandas Q130. ___________ refers to the process
of converting the structure to a byte stream
Ans. c. csv before writing it to the file.
a. pickling
Q126. Write the output of the following code b. unpickling
: c. reading
import csv d. writing
f = open(“data.csv”, ‘r’)
row = csv.reader(f) Ans. a. pickling
print(row)
a. It prints the memory address where
csv.reader object is stored
b. It prints the first record of data.csv Q131. Fill in the blank in the given code :
c. It prints all the records of data.csv import pickle
d. None of the above f = open("data.dat", "rb")
l = pickle._______(f)
Ans. a. It prints the memory address print(l)
where csv.reader object is stored f.close()
Q127. _________ function help us to read a. dump
the csv file. b. load
a. reader( ) c. write
b. read( ) d. list
c. read(n)
d. readline( ) Ans. b. load
Q132. Write the output of the following
Ans. a. reader( ) code:
Q128. Write the output of the second print f = open("data.txt","w")
statement of the given code: L=["My\n","name\n","is\n","amit"]
f.writelines(L) Ans. c. dump(L, f)
f.close()
f = open("data.txt","r") Q136. Which of the following statement will
print(len(f.read())) return attribute error?
a. 13 a. print(len(f.readlines( ).split( ))) #f is
b. 14 file handle
c. 15 b. print(len(f.readline( ).split( ))) #f is
d. 16 file handle
c. print(len(f.read( ).split( ))) #f is file
Ans. c. 15 handle
Q133. Write the output of the following d. None of the above
code:
f = open("data.txt","w") Ans. a. print(len(f.readlines( ).split( )))
L=["My\n","name\n","is\n","amit"] Q137. Ravi is writing a program for counting
f.writelines(L) the number of words in a text file named
f.close() “data.txt”. He has written the incomplete
f = open("data.txt","r") code. Help him to complete the code.
print(len(f.readlines())) f = open("_________","r") #
a. 4 Statement 1
b. 5 d = f._________ # Statement 2
c. 6 nw = d._________ # Statement 3
d. 7 print("Number of words are",
_________(nw)) # Statement 4
Ans. a. 4 Identify the suitable code for blank space in
Q134. Write the output of the following the line marked as Statement 1
code: a. “data.txt”
f = open("data.txt","w") b. data.txt
L=["My\n","name\n","is\n","amit"] c. “data”
f.writelines(L) d. data
f.close()
f = open("data.txt","r") Ans. b. data.txt
print(len(f.readline())) Q138. Identify the suitable code for blank
a. 2 space in the line marked as Statement
b. 3 2(Refer Q. 137)
c. 4 a. readlines( )
d. 5 b. readline( )
c. read( )
Ans. b. 3 d. None of the above
Q135. Fill in the blank in the given code :
import pickle Ans. c. read( )
f = open("data.dat", "wb") Q139. Identify the suitable code for blank
L = [1, 2, 3] space in the line marked as Statement
pickle._______ 3(Refer Q. 137)
f.close() a. split( )
a. dump(f, L) b. break( )
b. load(f, L) c. words( )
c. dump(L, f) d. jump( )
d. load(L, f)
Ans. a. split( )
Q140. Identify the suitable code for blank d. i
space in the line marked as Statement
4(Refer Q. 137) Ans. a. row
a. length Q145. Parth is writing a program to
b. len add/insert records in file “data.csv”. He has
c. Len written the following code. As a programmer,
d. Length help him to execute it successfully.
import csv
Ans. b. len field = [“Roll no” , “Name” , “Class”]
f = open(“_________” , ‘w’)
#Statement1
Q141. Ananya was writing a program of d=__________.writer(f)
reading data from csv file named “data.csv”. #Statement2
She writes the incomplete code. As a friend d.writerow(field)
of Ananya help her to complete the code. ch=’y’
________ csv #Statement1 while ch==’y’ or ch==’Y’:
f=open("data.csv", '_______') rn=int(input(“Enter Roll number: “))
#Statement2 nm = input(“Enter name: “)
d=csv.___________(f) #Statement3 cls = input(“Enter Class: “)
for __________ in d: #Statement4 rec=[_________] #Statement3
print(row) d.writerow(rec)
Identify the suitable option for Statement 1 ch=input(“Enter more record??(Y/N)”)
a. import f.close()
b. create Identify the correct statement for Statement
c. data 1
d. Import a. data
b. data.csv
Ans. a. import c. file_data.csv
Q142. Identify the correct option for d. None of the above
Statement2 (Refer Q 141)
a. w Ans. b. data.csv
b. a
c. rb Q146. Identify the correct statement for
d. r Statement 2. (Refer Q. 145)
a. CSV
Ans. d. r b. csv
Q143. Identify the correct option for c. file
Statement3 (Refer Q 141) d. csv_
a. readlines
b. readline Ans. b. csv
c. read Q147. Identify the correct statement for
d. reader Statement 3. (Refer Q. 145)
a. rollno, name, class
Ans. d. reader b. Roll no, Name, Class
Q144. Identify the correct option for c. rn, nm, cls
Statement4 (Refer Q 141) d. field
a. row
b. d Ans. c. rn, nm, cls
c. csv
Q148. Chinki is writing a program to copy _________________ bookshop:
the data from “data.csv” to “temp.csv”. #Statement 1
However she is getting some error in b_name = input("Enter book name:")
executing the following program due to some b_price=int(input("Enter book
missing commands. Help her to execute it price:"))
successfully. data =
import csv _________________([b_name,
f=open(“data.csv”,”r”) b_price]) #Statement 2
f1=open(“temp.csv”,’__________’) f = open("book.txt","w")
#Statement 1 f.write(_____________) #Statement
d=csv._________(f) #Statement 2 3
d1=csv.writer(f1) f.close()
for i in d: Identify the correct option for Statement 1.
___________.writerow(i) a. def
#Statement3 b. Def
f.close( ) c. define
f1.close( ) d. Define
Identify the correct statement for Statement
1. Ans. a. def
a. r Q152. Identify the correct option for
b. rb+ Statement 2.
c. wa a. int
d. w b. str
c. char
Ans. d. w d. float
Q149. Identify the correct statement for
Statement 2.(Refer Q148.) Ans. b. str
a. read Q153. Identify the correct option for
b. reader( ) Statement 3.
c. reader a. data
d. read(r) b. b_name
c. b_price
Ans. c. reader d. f
Q150. Identify the correct statement for Show Answer
Statement 2.(Refer Q148.) a. data
a. d
b. d1
c. f
d. f1

Ans. b. d1

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.

You might also like