This quiz works best with JavaScript enabled. Home > Class 11 > Class 11 Computer Science Chapter 6 File Handling – Quiz 29 🏠 Homepage 📘 Download PDF Books 📕 Premium PDF Books Class 11 Computer Science Chapter 6 File Handling Quiz 29 (25 MCQs) Quiz Instructions Select an option to see the correct answer instantly. 1. How can you read a file line by line in Python? A) Use 'file.read lines(filename)'. B) Use 'open(filename) as file:read(file)'. C) Use 'with open(filename) as file:file.readlines()'. D) Use 'with open(filename) as file:for line in file:process(line)'. Show Answer Correct Answer: D) Use 'with open(filename) as file:for line in file:process(line)'. 2. What is the purpose of the with statement when working with files? A) To open the file in read mode. B) To open the file in write mode. C) To ensure that the file is closed properly after use. D) To manipulate the data in the file. Show Answer Correct Answer: C) To ensure that the file is closed properly after use. 3. This function connects the file written on the disk with file object A) Read(). B) Close(). C) Open(). D) Write(). Show Answer Correct Answer: C) Open(). 4. What is the code to open a file named as My ..... Data for reading data from it? A) Open("My Data.dat", "ios::in"). B) Open(My Data.dat, "ios::in"). C) Open("My Data.dat", ios::in). D) Open(My Data.dat, ios::in). Show Answer Correct Answer: C) Open("My Data.dat", ios::in). 5. The file pointer is reset to the start of the file using: A) Rewind(). B) Seek(0). C) Reset(). D) Goto(0). Show Answer Correct Answer: B) Seek(0). 6. We don't need to be careful with the 'w' mode as it will not overwrite into the file if it already exists. A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: B) False. 7. What is the difference between 'r' and 'rb' file modes? A) Both 'r' and 'rb' modes are used for reading text files only. B) The 'r' mode is for writing text files, and 'rb' is for writing binary files. C) The 'r' mode is for reading binary files, and 'rb' is for reading text files. D) The 'r' mode is for reading text files, and 'rb' is for reading binary files. Show Answer Correct Answer: D) The 'r' mode is for reading text files, and 'rb' is for reading binary files. 8. What is the description of the following file mode 'w+' A) Write and read. B) Write only. C) Read only. D) None. Show Answer Correct Answer: A) Write and read. 9. File formats are specified in the file name A) TRUE. B) FALSE. C) All the above. D) None of the above. Show Answer Correct Answer: B) FALSE. 10. Which mode is used to write to a file (overwriting if exists)? A) 'r'. B) 'a'. C) 'w'. D) 'rw'. Show Answer Correct Answer: C) 'w'. 11. Which library is used in Python for binary file serialization? A) Pickle. B) Json. C) Csv. D) Struct. Show Answer Correct Answer: A) Pickle. 12. Which function is used to unpickle data from a binary file? A) Pickle.load(). B) Pickle.dump(). C) Pickle.read(). D) Pickle.write(). Show Answer Correct Answer: A) Pickle.load(). 13. What is the root folder on Windows typically referred to as? A) System folder. B) Home folder. C) Root directory. D) C:drive. Show Answer Correct Answer: D) C:drive. 14. Which function is used to check if the end of a file has been reached? A) EOF(). B) EndOfFile(). C) End(). D) IsEOF(). Show Answer Correct Answer: A) EOF(). 15. How can you ensure data is read one line at a time from a file? A) Use READFILE, and specify you want lines. B) Read the entire file and split the data into lines in the program. C) Use a loop to read until EOF, capturing data line by line. D) It's not possible to read data one line at a time. Show Answer Correct Answer: C) Use a loop to read until EOF, capturing data line by line. 16. 'w' mode creates a new file if one did not exist at the specified location. A) TRUE. B) FALSE. C) All the above. D) None of the above. Show Answer Correct Answer: A) TRUE. 17. Apa yang akan terjadi jika Anda mencoba membaca dari file yang tidak ada? A) Program akan berjalan normal. B) Program akan menampilkan pesan kesalahan. C) Data akan ditulis ke file. D) File akan dibuat secara otomatis. Show Answer Correct Answer: B) Program akan menampilkan pesan kesalahan. 18. How do you append text to a file? A) Using the 'read()' function. B) Using the 'r' mode. C) Using the 'w' mode. D) Using the 'a' mode. Show Answer Correct Answer: D) Using the 'a' mode. 19. What is the purpose of the program in Program 13.2? A) Write characters to a file. B) Read integers from a file. C) Copy source file to destination file. D) Append text to the end of a file. Show Answer Correct Answer: C) Copy source file to destination file. 20. Which type of file format is used to store tabular data like in a spreadsheet? A) MOV. B) MP3. C) CSV. D) TXT. Show Answer Correct Answer: C) CSV. 21. How do you create a Fileinputstream object in Java? A) FileInputStream input = new FileInputStream(file.txt);. B) FileInputStream input = new FileInputStream(file);. C) FileInputStream input = new FileInputStream("file.txt");. D) FileInputStream input = new FileInputStream();. Show Answer Correct Answer: C) FileInputStream input = new FileInputStream("file.txt");. 22. Select the statement to open a file named MYDATA.txt in read and write mode. Let the file object name be myfile. A) Myfile=open("MYDATA.dat", "rb+"). B) Myfile=open("MYDATA.dat", "r+"). C) Myfile=open("MYDATA.dat", "r"). D) None of the above. Show Answer Correct Answer: B) Myfile=open("MYDATA.dat", "r+"). 23. Which method is used to write text to a file in Python? A) File.append(). B) File.read(). C) File.write(). D) File.save(). Show Answer Correct Answer: C) File.write(). 24. What method is used to read a file line by line? A) Using 'readline()' method or iterating over the file object. B) Using 'close()' method. C) Using 'write()' method. D) Using 'read()' method. Show Answer Correct Answer: A) Using 'readline()' method or iterating over the file object. 25. What is the function of the 'getline' method in C++ file handling? A) To read a single character from the file. B) To read an entire line from the file. C) To write a line to the file. D) To check if the file is open. Show Answer Correct Answer: B) To read an entire line from the file. ← PreviousNext →Related QuizzesClass 11 Computer Science Chapter 6 File Handling Quiz 1Class 11 Computer Science Chapter 6 File Handling Quiz 2Class 11 Computer Science Chapter 6 File Handling Quiz 3Class 11 Computer Science Chapter 6 File Handling Quiz 4Class 11 Computer Science Chapter 6 File Handling Quiz 5Class 11 Computer Science Chapter 6 File Handling Quiz 6Class 11 Computer Science Chapter 6 File Handling Quiz 7Class 11 Computer Science Chapter 6 File Handling Quiz 8Class 11 Computer Science Chapter 6 File Handling Quiz 9Class 11 Computer Science Chapter 6 File Handling Quiz 10 🏠 Back to Homepage 📘 Download PDF Books 📕 Premium PDF Books