Class 12 Computer Science File Handling in Python MCQs Set 6

Python File Handling



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

Answer : 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()

Answer : b) read()

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()

Answer : c) line.split()

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

Answer : b) len(c) < 4

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 : a) 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

Answer : 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()

Answer : a) file.read()

108. Fill in the blank in #Statement-3 to read data by for loop.

a) Line

b) File.Lines

c) data

d) Lines

Answer : 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()

Answer : c) L.upper()

110. Fill in the blank in #Statement-5 to close the file.

a) flie.close()

b) file.close

c) close(file)

d) file.close()

Answer : 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)

Answer : c) file.seek(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.

Answer : 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.

Answer : a) is specify the reference position i.e. start position.

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

Answer : 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

Answer : b) 30

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

Answer : c) 50

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

Answer : a) 70

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

Answer : c) 15

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

Answer : 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

Answer : b) path


More MCQ’s are on the way, Refresh your page…

Python File Handling (MCQ’s)


Python Revision Tour – Multiple Choice Questions (MCQ’s)


Python Functions – Working with Functions (MCQ’s)


Thanks for visiting. Online Classes are available.

You cannot copy content of this page

Scroll to Top