Refer to CBSE Class 12 Computer Science Text File MCQs provided below available for download in Pdf. The MCQ Questions for Class 12 Computer Science with answers are aligned as per the latest syllabus and exam pattern suggested by CBSE, NCERT and KVS. Multiple Choice Questions for Text File are an important part of exams for Class 12 Computer Science and if practiced properly can help you to improve your understanding and get higher marks. Refer to more Chapter-wise MCQs for CBSE Class 12 Computer Science and also download more latest study material for all subjects
MCQ for Class 12 Computer Science Text File
Class 12 Computer Science students should refer to the following multiple-choice questions with answers for Text File in Class 12.
Text File MCQ Questions Class 12 Computer Science with Answers
Question. Which of the following command is used to open a file “c:\temp.txt” in read-mode only?
a) infile = open(“c:\temp.txt”, “r”)
b) infile = open(“c:\\temp.txt”, “r”)
c) infile = open(file = “c:\temp.txt”, “r+”)
d) infile = open(file = “c:\\temp.txt”, “r+”)
Answer : B
Question. Which of the following commands can be used to read “n” number of characters from a file using the file object <file>?
a) read(n)
b) n = file.read()
c) file.readline(n)
d) file.readlines()
Answer : A
Question. Which of the following commands can be used to read the remaining lines in a file using the file object <tmpfile>?
a) read(n)
b) read()
c) readline()
d) readlines()
Answer : C
Question. Each line of a text file is terminated by a special character, called?
a) End of file
b) End of byte
c) End of line
d) All the above
Answer : C
Question. Which function is used to read single line from file?
a) readline()
b) readlines()
c) readstatement()
d) readfullline()
Answer : A
Question. What is the expected output of the given code?
f = None
for i in range (5):
with open(“data.txt”, “w”) as f:
if i > 2:
break
print(f.closed)
a) True
b) False
c) None
d) Error
Answer : A
Question. Which method of pickle module is used to write onto a binary file?
a) dump()
b) load()
c) All of the above
d) None of the above
Answer : A
Question. Which of the following command is used to open a file “c:\temp.txt” in append-mode?
a) outfile = open(“c:\temp.txt”, “a”)
b) outfile = open(“c:\\temp.txt”, “rw”)
c) outfile = open(“c:\temp.txt”, “w+”)
d) outfile = open(“c:\\temp.txt”, “r+”)
Answer : A
Question. Which of the following commands can be used to read the next line in a file using the file object <tmpfile>?
a) read(n)
b) tmpfile.read()
c) readline()
d) tmpfile.readlines()
Answer : C
Question. Which of the following statements is not True
a) File method close() closes the opened file.
b) Python automatically closes a file when the reference object of a file is reassigned to another file.
c) close() method returns a value which ensures the termination of the file stream
d) Calling close( ) method more than once is allowed.
Answer : C
Question. The files that consists of human readable characters
a) Text file
b) Binary file
c) Both Text and Binary file
d) None of the above.
Answer : A
Question. Which function is used to close a file in python?
a) close()
b) stop()
c) end()
d) closefile()
Answer : A
Question. Which of the following file modes opens a file for appending and reading in a binary file and moves the files pointer at the end of the file if the file already exists or creates a new file?
a) a
b) a+
c) ab+
d) ab
Answer : C
Question. Which of the following commands can be used to read the entire contents of a file as a string using the file object <tmpfile>?
a) read(n)
b) read()
c) readline()
d) readlines()
Answer : B
Question. Which of the following statements is true with respect to the files in Python?
a) File can be opened with a file handle using open method without any arguments
b) File can be opened with a file handle using open method with one argument to read the file
c) File can be opened with a file handle using open method with one argument to write the file
d) File can be opened with a file handle using open method with one argument to append the file
Answer : B
Question. How many types of files are there in python?
a) 1
b) 2
c) 3
d) 4
Answer : B
Question. In file handling, what does this terms means “r, a”?
a) read, append
b) append, read
c) write, append
d) none of the mentioned
Answer : A
Question. Which of the following statements is/are true?
a) When you open a file for reading, if the file does not exist, an error occurs.
b) When you open a file for writing, if the file does not exist, a new file is created.
c) When you open a file for writing, if the file exists, the existing file is overwritten with the new file. (
d) All of the above.
Answer : D
Question. Which of the following command is used to open a file “c:\temp.txt” in write-mode only
a) outfile = open(“c:\temp.txt”, “w”)
b) outfile = open(file = “c:\temp.txt”, “w+”)
c) outfile = open(file = “c:\\temp.txt”, “w+”)
d) outfile = open(“c:\\temp.txt”, “w”)
Answer : D
Question. What does the <readlines()> method returns?
a) Str
b) a list of lines
c) list of single characters
d) list of integers
Answer : B
Question. To open a file only for reading which of the following statement cannot be used :
a) f = open(“PYTHON.txt”)
b) f = open(“PYTHON.txt”, “rt”)
c) f = open(“PYTHON.txt”, “r”)
d) f = open(“PYTHON.txt”,”r+”)
Answer : D
Question. Trying to open a binary file using a text editor will show:
a) Garbage values
b) ASCII values
c) Binary character
d) Unicodes
Answer : A
Question. A file maintains a __________ which tells the current position in the file where writing or reading will take place.
a) line
b) file pointer
c) list
d) order
Answer : B
Question. Rahul is assigned the task of storing the information of his class mates as student records in a text file “Stu2021.txt”.He wants to create a file to write the records. Which of the following is not a valid mode to open a file for writing the data?
a) w
b) r+
c) r
d) w+
Answer : C
Question. Ajay is studying in an Engineering College in CSE branch. His sister, a class 12 student of Computer Science comes to him one day asking him the difference between r+ and w+ modes of a file. What is the correct answer Ajay would give to his sister?
a) No difference between r+ and w+
b) In r+ mode, the file is created if it does not exist and erases the content if the file already exists; w+ raises an error if the file does not exist
c) In w+ mode, the file is created if it does not exist and erases the content if the file already exists; r+ raises an error if the file does not exist
d) Depends on the operating system
Answer : C
Case Study Questions on Text File
Question. Aishwarya is running her own boutique business. She wants to store data of all orders permanently and fast processing of data through her boutique software. Suggest her to choose the appropriate technique among the following.
a) She can use Python Dictionaries with Text files.
b) She can use Python Dictionaries with Binary file concept.
c) She can use Python Lists without the Binary files concept.
d) She can use Python Dictionaries without the Binary file concept.
Answer : B
Question. Given the directory structure in Q 23. Assume that the CWD is in the feline folder. What is the relative path to the file bears.gif?
a) C:/animals/ursine
b) animals/ursine
c) ..ursine/bears.gif
d) None of the above.
Answer : C
Question. In a program, there is a need of reading whole content of a textfile in a single shot and store it in the form of list. Suggest the best option among the following
a) read()
b) readline()
c) readlines()
d) None of the above
Answer : C
Question. A Student’s windows O/S got corrupted. He is trying to access his files through Command Prompt, but unable to find out all his Binary data files pertaining to his project. Help him to find out all his binary data files by suggesting the suitable extension name among the following.
a) .txt
b) .bin
c).dat
d) .com
Answer : C
Question. Given the directory structure in Q 23. Assume that the CWD is in the feline folder what is the relative path to lions.gif?
a) C:/animals/ursine
b) lions.gif
c) /animals/ursine/bears.gif
d) None of the above.
Answer : B
Question. A programmer has confusion in understanding the behaviour of opening a file in “w” mode. Clear his/her confusion, by suggesting the correct option among the given below. The behaviour of “w” mode is
a) Opening fails if the file already exists already.
b) Opening fails if the file does not exist already.
c) Opening will be succeeded if file exists with data and keeps the data intact.
d) Opening will be succeeded, if the file exists replaces the contents, do not exist, creates a new file.
Answer : D
Question. Given the directory structure in Q 23. Assume that the CWD is in the root folder where animals directory resides. What is the absolute path to bears.gif?
a) C:/animals/ursine
b) ../animals/feline
c) /animals/ursine/bears.gif
d) None of the above.
Answer : C
Question. Aditya is a class 12 student like you. He is practicing text file programming. He has a text file named names.txt. He wants to display all the names contained in the text file. He has written one of the following codes and succeeded in getting the output. Guess which among the following option might have given the correct output.
a) names = open(“names.txt”, “r”)
for line in names:
print(names)
c) names = open(“names.txt”, “r”)
for line in names:
print(“line”)
b) names = open(“names.txt”, “r”)
for line in names:
print(line)
d) names = open(“names.txt”, “r”)
for names in line:
print(line)
Answer : B
Question. Master Adithya could able to read contents of a text file part by part. Out of the following which option he would have been used?
a) read()
b) readlines()
c) readline()
d) readfullline()
Answer : C
Rohit of class 12 is asked by his Computer Science teacher to count the number of “the” and “and” in a text file “Book.txt”. He was able to do the task to some extent, but was confused in some areas. Help him out to complete the task
def displaytheand():
num=0 _________ #Statement 1
N=f.read()
M=N.split()
for x in M:
if x==”the” or x== “and”:
print(x) num=num+1 __________ #Statement 2
print(“Count of the/My in and:”,num)
Question. Identify the correct statement that may be used in the place of statement 2
a) f.close()
b) f.close(“book.txt”)
c) close()
d) None of the above
Answer : A
Question. Which of the following is the correct one to be used in the place of statement 1
a) f=open(“Book.txt”,”w”)
b) f=open(“Book.txt”,”r”)
c) f=open(“Book.txt”,”a”)
d) F=open(“Book.txt”,”r”)
Answer : B
Rajitha, during Practical Examination of Computer Science, has been assigned an incomplete search() function to search in a text file “CAMP.txt”. The file “CAMP.txt” is created by his Teacher and the following information is known about the file
i) File contains details of camp describing events of an adventure camp in text format
ii) File contains details of adventure activities like caving, trekking, paragliding, rafting and rock climbing Rajitha has been assigned the task to complete the code and print the number of the word trekking
def search():
f = open(“CAMP.txt”,____) #Statement-1
A=____________________ #Statement-2
ct=0
for x in A:
p=x.split()
if p==”trekking”:
ct+=1
print(ct) _______________________# Statement-3
Question. In which mode Rajitha should open the file in Statement-1?
a) r
b) r+
c) rb
d) wb
Answer : A
Question. Which statement should Rajitha use in Statement 3 to close the file.
a) file.close()
b) close(file)
c) f.close()
d) close()
Answer : C
Question. Name the function that can be used by Rajitha to read the content of the file in statement -2.
a) f.read( )
b) f.readline ()
c) f.readlines( )
d) f.readl()
Answer : C
Aparajitha joined an MNC company in Bangalore as a Python Programmer. Her task is to handle the data available for the company in the form of text files and perform the search operations based on specific criteria. Now she is asked to count the number of words in the file which start with “a” or “m” (both upper and lower cases) in a text file “Passion.txt”. She needs your help as she is stuck up with some statements. Please help her out to complete the task
def filecreate():
f=open(“Passion.txt”,”r”) #Statement 1
f.write() f.close() # Statement 2
def count_A_M():
f=open(“Passion.txt”,”r”) # Statement 3
A,M=0,0
r=f.read()
for x in r:
if x[0]==”A” or x[0]==”a” :
A=A+1 25 elif x[0]==”M” or x[0]==”m”: M=M+1
f.close()
print(“A or a: “,A)
print(“M or m: “,M)
Question. Which of the following options can be used as statement 3
a) f=open(“Passion.txt”,”r”)
b) f=open(“Passion.txt”,”w”)
c) f=open(“Passion.txt”,”a”)
d) f=open(“Passion.txt”,”rt”)
Answer : A, B
Question. Choose the correct option to be used as statement 1
a) f=open(“Passion.txt”,”r”)
b) f=open(“Passion.txt”,”r+”)
c) f=open(“Passion.txt”,”w”)
d) f=open(“Passion.txt”,”a”)
Answer : C
Question. Choose the correct option to be used as statement 2
a) F.close()
b) f.close()
c) F.close(“passion.txt”)
d) No statement is required
Answer : B
Text file: opening a text file, text file open modes (r, r+, w, w+, a, a+), closing a text file, opening a file using with clause
Question. The mode “w+” is used to open the file for
a) Read and write a text file
b) Read and write a binary file
c) Write and Read a text file
d) Write and Read a binary file
Answer : C
Question. In r+ mode, if we write the file directly, it will
a) overwrite the beginning content
b) continue reading from the previous content
c) continue writing from the previous content
d) work like the append mode
Answer : A
Question. What is the default mode when the file is opened using the open() method ?
a) Write
b) Read
c) Write and read
d) Read and write
Answer : B
Question. Which of the following statements is true?
a) Python doesn’t write data to the file until you close the file using the close() method
b) If the file is opened for writing and is not closed, data is not written into the target file.
c) Python can write data to the file even if you do not close the file
d) None of the above
Answer : B
Question. (A) : If a file is opened using the “with” statement, you get better syntax and exceptions handling.
(B): When a file is opened using the “with” statement, it need not be closed using the close() function.
In the above two statements, which of the following is true?
a) Both A and B are Wrong
b) A is Wrong, but B is right.
c) A is right , but B is Wrong
d) Both A and B are right.
Answer : D
Question. The function read() is used to
a) Read the entire content of the file
b) Read the entire content of the file in the form of list
c) Read the content of the file line by line
d) Read each string of the content of the file
Answer : A
Question. When a file is opened in “w” mode, the file pointer is placed at
a) the beginning of the file.
b) The end of the file.
c) the middle of the file.
d) the current position of the file.
Answer : A
Question. When the file content has to be modified, we can use the ____________ mode
a) r
b) w
c) a
d) r+
Answer : A
Question. Which of the following statements is true with respect to closing a file
a) It is mandatory to close a text file which is opened
b) Python automatically closes a file
c) Python automatically closes a file if the reference object of the file is allocated to another
d) None of the above
Answer : C
Question. When a file is opened in “a” mode, the file pointer is placed at
a) the beginning of the file.
b) The end of the file.
c) the middle of the file.
d) the current position of the file.
Answer : B
CBSE Class 12 Computer Science Cascading Style Sheets and JavaScript MCQs |
CBSE Class 12 Computer Science Classes and Objects In Java MCQs Set A |
CBSE Class 12 Computer Science Classes and Objects In Java MCQs Set B |
CBSE Class 12 Computer Science Computer Hardware MCQs |
CBSE Class 12 Computer Science Creating HTML Forms Using KompoZer MCQs Set A |
CBSE Class 12 Computer Science Creating HTML Forms Using KompoZer MCQs Set B |
CBSE Class 12 Computer Science Data Structure MCQs |
CBSE Class 12 Computer Science Database Management System MCQs |
CBSE Class 12 Computer Science Designing Simple Website Using Kompozer MCQs |
CBSE Class 12 Computer Science Exception Handling In Java MCQs |
CBSE Class 12 Computer Science File Handling MCQs Set A |
CBSE Class 12 Computer Science File Handling MCQs Set B |
CBSE Class 12 Computer Science File System MCQs Set A |
CBSE Class 12 Computer Science File System MCQs Set B |
CBSE Class 12 Computer Science Flow of control conditional statements MCQs |
CBSE Class 12 Computer Science For Loop in Python MCQs |
CBSE Class 12 Computer Science Fundamentals of Computer MCQs |
CBSE Class 12 Computer Science Introduction To E Commerce MCQs |
CBSE Class 12 Computer Science Introduction To M Commerce MCQs Set A |
CBSE Class 12 Computer Science Introduction To M Commerce MCQs Set B |
CBSE Class 12 Computer Science Java Basics MCQs Set A |
CBSE Class 12 Computer Science Java Basics MCQs Set B |
CBSE Class 12 Computer Science Object Oriented Concepts MCQs |
CBSE Class 12 Computer Science Publishing Documents Using Latex MCQs Set A |
CBSE Class 12 Computer Science Publishing Documents Using Latex MCQs Set B |
CBSE Class 12 Computer Science Working with Function in Python MCQs |
MCQs for Text File Computer Science Class 12
Expert teachers of studiestoday have referred to NCERT book for Class 12 Computer Science to develop the Computer Science Class 12 MCQs. If you download MCQs with answers for the above chapter you will get higher and better marks in Class 12 test and exams in the current year as you will be able to have stronger understanding of all concepts. Daily Multiple Choice Questions practice of Computer Science will help students to have stronger understanding of all concepts and also make them expert on all critical topics. After solving the questions given in the MCQs which have been developed as per latest books also refer to the NCERT solutions for Class 12 Computer Science. We have also provided lot of MCQ questions for Class 12 Computer Science so that you can solve questions relating to all topics given in each chapter. After solving these you should also refer to Class 12 Computer Science MCQ Test for the same chapter.
You can download the CBSE MCQs for Class 12 Computer Science Text File for latest session from StudiesToday.com
Yes, the MCQs issued by CBSE for Class 12 Computer Science Text File have been made available here for latest academic session
You can find CBSE Class 12 Computer Science Text File MCQs on educational websites like studiestoday.com, online tutoring platforms, and in sample question papers provided on this website.
To prepare for Text File MCQs, refer to the concepts links provided by our teachers and download sample papers for free.
Yes, there are many online resources that we have provided on studiestoday.com available such as practice worksheets, question papers, and online tests for learning MCQs for Class 12 Computer Science Text File