Python File Handling
- Class 12 Computer Science File Handling in Python MCQs Set 1
- Class 12 Computer Science File Handling in Python MCQs Set 2
- Class 12 Computer Science File Handling in Python MCQs Set 3
- Class 12 Computer Science File Handling in Python MCQs Set 4
- Class 12 Computer Science File Handling in Python MCQs Set 5
- Class 12 Computer Science File Handling in Python MCQs Set 6
- Class 12 Computer Science File Handling in Python MCQs Set 7
- Class 12 Computer Science File Handling in Python MCQs Set 8
- Class 12 Computer Science File Handling in Python MCQs Set 9
File Handling in Python MCQ’s Set – 6
Multiple Choice Questions
Answer Que Number 101 to 105 on the basis of given instructions and code.
Your teacher has given you a method/function FilterWords() in python which read lines from a text file NewsLetter.TXT, and display those words, which are lesser than 4 characters. Your teachers intentionally kept few blanks in between the code and asked you to fill the blanks so that the code will run to find desired result. Do the needful with the following python code.
def FilterWords():
c=0
file=open('NewsLetter.TXT', '_____') #Statement-1
line = file._____ #Statement-2
word = _____ #Statement-3
for c in word:
if _____: #Statement-4
print(c)
_________ #Statement-5
FilterWords()
101. Write mode of opening the file in #Statement-1?
a) a
b) ab
c) w
d) r
102. Fill in the blank in #Statement-2 to read the data from the file.
a) File.read()
b) read( )
c) read.lines( )
d) readlines()
103. Fill in the blank in #Statement-3 to read data word by word.
a) Line.Split()
b) Line.split( )
c) line.split( )
d) split.word()
104. Fill in the blank in #Statement-4, which display the word having lesser than 4 characters.
a) len(c) == 4
b) len(c) < 4
c) len() == 3
d) len(c) == 3
105. Fill in the blank in #Statement-5 to close the file.
a) file.close()
b) file.close
c) close(file)
d) File.close()
Answer Que Number 106 to 110 on the basis of given instructions and code.
Pooja wants to write a function Show_words() in python to read the content of a text file ‘NOTES.TXT’ and display the entire content in capital letters. She has written some lines of program but facing some problems in some statements. Help Pooja and fill the missing statement to complete the program.
Example, if the file contains:
“This is a test file”
Then the function should display the output as:
THIS IS A TEST FILE
She has written coding:
def Show_words():
file = open(‘NOTES.TXT’,' ') #statement 1
Lines = _______ #statement 2
for L in ________: #statement 3
print(__________) #statement 4
_____.close() #statement 5
Show_words()
106. Write mode of opening the file in #Statement-1?
a) a
b) ab
c) w
d) r
107. Fill in the blank in #Statement-2 to read the data from the file.
a) file.read()
b) read.file( )
c) read.lines( )
d) readlines()
108. Fill in the blank in #Statement-3 to read data by for loop.
a) Line
b) File.Lines
c) data
d) Lines
109. Fill in the blank in #Statement-4, which display the word having lesser than 4 characters.
a) L.ucase()
b) L.ucase
c) L.upper()
d) L.toupper()
110. Fill in the blank in #Statement-5 to close the file.
a) flie.close()
b) file.close
c) close(file)
d) file.close()
111. Which command is used to move the file pointer at 5 position in text file.
a) flie.tell(5)
b) file.goto(5)
c) file.seek(5)
d) seek(file, 5)
112. In the given syntax, what is offset?
file_object.seek(offset, mode)
a) is specify the current location
b) is specify the position of cursor in current location
c) is specify the size of file
d) is a number specifying number of bytes.
113. In the given syntax, what is mode?
file_object.seek(offset, mode)
a) is specify the reference position, i.e. start position
b) is specify the position of cursor in current location
c) is specify the size of file
d) is a number specifying number of bytes.
114. Identify which is a valid types of mode?
file_object.seek(offset, mode)
a) 0 – Begining
b) 1 – Current
c) 2 – End
d) All of these
115. What is the new file pointer position, if the current position is 20.
file_object.seek(30, 0)
a) 0
b) 30
c) 50
d) None of these
116. What is the new file pointer position, if the current position is 20 and size of the file is 100.
file_object.seek(30, 1)
a) 0
b) 30
c) 50
d) None of these
117. What is the new file pointer position, if the current position is 20 and size of the file is 100.
file_object.seek(-30, 2)
a) 70
b) 30
c) 50
d) None of these
118. What is the new file pointer position, if the current position is 20 and size of the file is 100.
file_object.seek(-5, 1)
a) 0
b) 30
c) 15
d) None of these
119. In Python, you can open a file with the help of _________ function/statement.
a) file_object = open(filename, filemode)
b) with open( filename, filemode ) as fileobject
c) fileobject = file(filename, filemode)
d) All of these
120. ______ is a sequence of directory names which give you the hierarchy to access a particular directory or file name.
a) folder name
b) path
c) file name
d) None of these
Python File Handling (MCQ’s)
- Class 12 Computer Science File Handling in Python MCQs Set 1
- Class 12 Computer Science File Handling in Python MCQs Set 2
- Class 12 Computer Science File Handling in Python MCQs Set 3
- Class 12 Computer Science File Handling in Python MCQs Set 4
- Class 12 Computer Science File Handling in Python MCQs Set 5
- Class 12 Computer Science File Handling in Python MCQs Set 6
- Class 12 Computer Science File Handling in Python MCQs Set 7
- Class 12 Computer Science File Handling in Python MCQs Set 8
- Class 12 Computer Science File Handling in Python MCQs Set 9
Python Revision Tour – Multiple Choice Questions (MCQ’s)
- Class 12 Computer Science MCQs Python Revision Tour Set – 1
- Class 12 Computer Science MCQs Python Revision Tour Set – 2
Python Functions – Working with Functions (MCQ’s)
- Class 12 Computer Science Python Functions – Working with Functions MCQs Set – 1
- Class 12 Computer Science Python Functions – Working with Functions MCQs Set – 2
- Class 12 Computer Science Python Functions – Working with Functions MCQs Set – 3
- Class 12 Computer Science Python Functions – Working with Functions MCQs Set – 4
- Class 12 Computer Science Python Functions – Working with Functions MCQs Set – 5
- Class 12 Computer Science Python Functions – Working with Functions MCQs Set – 6
Thanks for visiting. Online Classes are available.