This quiz works best with JavaScript enabled. Home > Cbse > Class 11 > Science > Computer Science > Class 11 Computer Science Chapter 6 File Handling – Quiz 6 🏠 Homepage 📘 Download PDF Books 📕 Premium PDF Books Class 11 Computer Science Chapter 6 File Handling Quiz 6 (60 MCQs) Quiz Instructions Select an option to see the correct answer instantly. 1. What does the function fopen() do? A) Closes an open file. B) Writes data to a file. C) Opens a file. D) Reads data from a file. Show Answer Correct Answer: C) Opens a file. 2. ..... Open the file for reading and writing. For existing file, data is truncated and over-written. A) Rw. B) W+. C) W. D) Wr. Show Answer Correct Answer: B) W+. 3. What is the significance of the Reader function in CSV file handling? A) The significance of the Reader function is to enable the processing of large CSV files without overwhelming system memory. B) The Reader function is used to convert CSV files into images. C) Reader function is designed to sort CSV files based on file size. D) Reader function allows for real-time editing of CSV files. Show Answer Correct Answer: A) The significance of the Reader function is to enable the processing of large CSV files without overwhelming system memory. 4. How can you create a new directory using pathlib? A) Using the create directory() method. B) Using the mkdir() method. C) All the above. D) None of the above. Show Answer Correct Answer: B) Using the mkdir() method. 5. What is the first step in handling a file in Python? A) Close the file. B) Write to the file. C) Read the file. D) Open the file. Show Answer Correct Answer: D) Open the file. 6. Which of these class is not related to input and output stream in terms of functioning? A) Write. B) InputStream. C) Reader. D) File. Show Answer Correct Answer: D) File. 7. The other names of pickling and unpickling is? A) Serialisation and deserialisation. B) Dump and load. C) Tell and seek. D) None of the above. Show Answer Correct Answer: A) Serialisation and deserialisation. 8. Formal and actual parameters are matched up by A) Position. B) ID. C) Name. D) Interests. Show Answer Correct Answer: A) Position. 9. What method would you use to close a file in Python? A) File.stop(). B) File.quit(). C) File.close(). D) File.end(). Show Answer Correct Answer: C) File.close(). 10. What is the default mode in which a file is opened using 'ifstream'? A) Read mode. B) Binary mode. C) Append mode. D) Write mode. Show Answer Correct Answer: A) Read mode. 11. Pickle. dump() takes two arguments namely ..... and ..... A) Fileobject, file handle of the open file. B) File handle of the open file. C) File handle of the open file, fileobject. D) All of the above. Show Answer Correct Answer: A) Fileobject, file handle of the open file. 12. Which is the correct statement for binary file reading? A) Data=fobj.read(). B) Data=pickle.dump(fobj). C) Pickle.load(data, fobj). D) Data=pickle.load(fobj). Show Answer Correct Answer: D) Data=pickle.load(fobj). 13. Most commonly used delimiter in a CSV file is A) :. B) . C) ,. D) /. Show Answer Correct Answer: C) ,. 14. Which of the following is a valid way to append data to a file? A) F = open('file.txt', 'r'). B) F = open('file.txt', 'a'). C) F = open('file.txt', 'x'). D) F = open('file.txt', 'w'). Show Answer Correct Answer: B) F = open('file.txt', 'a'). 15. If we want to do the same thing regardless of the error type that occurs in the try block, which should we use? A) Except:. B) Except ErrorType:. C) All the above. D) None of the above. Show Answer Correct Answer: A) Except:. 16. Which of the following commands can be used to read the remaining lines in a file using the file object ? A) Tmpfile.read(n). B) Tmpfile.readlines(). C) Tmpfile.read(). D) Tmpfile.readline(). Show Answer Correct Answer: B) Tmpfile.readlines(). 17. Which function will remove a file from the directory? A) Os.delete(). B) Os.path.delete(). C) Os.remove(). D) Os.path.remove(). Show Answer Correct Answer: D) Os.path.remove(). 18. What does the 'readline()' function do? A) Reads one line from the file. B) Reads the entire file at once. C) Writes a new line in the file. D) Deletes a line from the file. Show Answer Correct Answer: A) Reads one line from the file. 19. What is the purpose of rename()? A) Opens a file. B) Checks for end of file. C) Renames a file. D) Deletes a file. Show Answer Correct Answer: C) Renames a file. 20. What is the purpose of the 'with' statement in file handling? A) The 'with' statement in file handling is used to ensure that files are properly opened and closed. B) To append data to a file without opening it first. C) To create a new file without closing it afterwards. D) To read the contents of a file into memory. Show Answer Correct Answer: A) The 'with' statement in file handling is used to ensure that files are properly opened and closed. 21. What happens if you try to read from a file that has been opened in write mode? A) Reading from a file opened in write mode will result in an error. B) The content will be written to the file instead of being read. C) The file will be opened in read mode automatically. D) The file will be read successfully without any issues. Show Answer Correct Answer: A) Reading from a file opened in write mode will result in an error. 22. What will be the output of the following statement in python? (fh is a file handle) fh.seek(-30, 2) Options:-It will place the file pointer:- A) At 30th byte from the beginning of the file. B) At 30 bytes behind from end-of file. C) At 5 bytes behind from end-of file . D) At 30th byte ahead of current current file pointer position. Show Answer Correct Answer: B) At 30 bytes behind from end-of file. 23. Which function writes a character to a file? A) Putfile(). B) Fputc(). C) Write(). D) Fileput(). Show Answer Correct Answer: B) Fputc(). 24. What mode would you use to write to a file, overwriting its contents? A) R. B) A. C) A+. D) W. Show Answer Correct Answer: D) W. 25. Appending to a file means adding extra data into the file. A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: A) True. 26. Which step creates a connection between a file and a program? A) Close the file. B) Open the file. C) Read the file. D) Process the file. Show Answer Correct Answer: B) Open the file. 27. Explain the process of reading from a file in Python. A) Open the file $\rightarrow$ Write the contents using 'write' method $\rightarrow$ Close the file. B) Open the file $\rightarrow$ Read the contents using 'read' method $\rightarrow$ Close the file. C) Open the file $\rightarrow$ Read the contents using 'print' method $\rightarrow$ Close the file. D) Read the file $\rightarrow$ Execute the contents $\rightarrow$ Close the file. Show Answer Correct Answer: B) Open the file $\rightarrow$ Read the contents using 'read' method $\rightarrow$ Close the file. 28. What is the output of following program#include int main(){ extern int i; printf("%d ", i); { int i = 10; printf("%d ", i); } return 0; } A) 0 10. B) 10 10. C) 0 0. D) Compiler error. Show Answer Correct Answer: D) Compiler error. 29. Which of the following needs to be used to provide access to the file throughout a program? A) File writer. B) File type. C) File descriptor. D) File changer. Show Answer Correct Answer: C) File descriptor. 30. ..... method writes all given rows to the csv file. A) Writelines(). B) Writerow(). C) Writerows(). D) Writeln(). E) Writeline(). Show Answer Correct Answer: C) Writerows(). 31. Full form of CSV. A) Comma Separated Values. B) Core Subject Value. C) Case Sensitive Value. D) Case Separated Values. Show Answer Correct Answer: A) Comma Separated Values. 32. Simple programs can't make use of text files to store data for access again A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: B) False. 33. The default file mode is ..... mode: A) W. B) R. C) R+. D) W+. Show Answer Correct Answer: B) R. 34. Which statement is TRUE about file reading in Python? A) Read() reads line by line. B) Read() returns list of strings. C) Readline() reads the whole file. D) Readlines() reads entire file into a list. Show Answer Correct Answer: D) Readlines() reads entire file into a list. 35. What is the purpose of the 'with' statement when handling files? A) The 'with' statement is a method for encrypting file contents. B) The 'with' statement is used to read files line by line. C) The 'with' statement ensures proper management of file resources by automatically closing the file after its block of code is executed. D) The 'with' statement allows multiple files to be opened simultaneously. Show Answer Correct Answer: C) The 'with' statement ensures proper management of file resources by automatically closing the file after its block of code is executed. 36. What keyword in Python is used to load other Python source code files into your current code page? A) Load. B) Include. C) Import. D) Require. Show Answer Correct Answer: C) Import. 37. The data files are the files that stored ..... to specific application for later use. A) Hard Disk. B) Files. C) Data. D) Database. Show Answer Correct Answer: C) Data. 38. File data.txt contains "Hello" .f=open("data.txt", "w")f.write("World")f.close()What will be the content of file? A) Error. B) WorldHello. C) World. D) HelloWorld. Show Answer Correct Answer: C) World. 39. What will the following code do?with open('test.txt', 'w') as file:file.write("Hello World") A) Raise an error because the file doesn't exist. B) Append "Hello World" to 'test.txt'. C) Read the contents of 'test.txt'. D) Write "Hello World" to 'test.txt'. Show Answer Correct Answer: D) Write "Hello World" to 'test.txt'. 40. How do you create a Fileoutputstream object in Java? A) FileOutputStream.write("filename.txt"). B) FileOutputStream.create("filename.txt"). C) New FileOutputStream("filename.txt"). D) FileOutputStream.open("filename.txt"). Show Answer Correct Answer: C) New FileOutputStream("filename.txt"). 41. Fseek(fp, 0, SEEK ..... SET) moves pointer to: A) End. B) Middle. C) Beginning. D) Specific char. Show Answer Correct Answer: C) Beginning. 42. Which Tkinter widget is used for drawing shapes and graphics? A) Message Widget. B) Canvas Widget. C) Entry Widget. D) Slider. Show Answer Correct Answer: B) Canvas Widget. 43. Which is used for writing data to a file in file handling? A) FileInputStream. B) FileOutputStream. C) Both A & B. D) None of the above. Show Answer Correct Answer: B) FileOutputStream. 44. The ..... block holds the code to be run (Run the code) checked for any error, if exists A) Try. B) Except. C) Else. D) Finally. Show Answer Correct Answer: A) Try. 45. What does two periods (dot-dot) mean in a path? A) This directory. B) The parent folder. C) All the above. D) None of the above. Show Answer Correct Answer: B) The parent folder. 46. What is the purpose of the 'a' mode when opening a file in Python? A) It indicates that the file is being opened in append mode for text data. B) It signifies that the file is being opened in read mode for binary data. C) It specifies that the file is being opened in write mode for text data. D) It signifies that the file is being opened in read mode specifically for text data. Show Answer Correct Answer: A) It indicates that the file is being opened in append mode for text data. 47. To open a file poem.txt for reading, the correct syntax is ..... A) File=open(file='poem.txt', 'r'). B) File=open('poem.txt', 'r'). C) Fileopen=('poem.txt', 'r'). D) F=('poem.txt', 'w'). Show Answer Correct Answer: B) File=open('poem.txt', 'r'). 48. What does opening a file in mode 'a' mean?with open("test.txt ", 'a') as f: A) Open test.txtfor reading. B) Open test.txtfor writing. C) Open test.txt for appending text at the end of the file. D) None of the file. Show Answer Correct Answer: C) Open test.txt for appending text at the end of the file. 49. Public class X { public static void main(String [] args) { try { badMethod(); System.out.print("A"); } catch (Exception ex) { System.out.print("B"); } finally { System.out.print("C"); } System.out.print("D"); } public static void badMethod() { throw new Error(); /* Line 22 */ } } A) ABCD. B) C is printed before exiting with an error message. C) Compilation fails. D) BC is printed before exiting with an error message. Show Answer Correct Answer: B) C is printed before exiting with an error message. 50. Files are having ..... nature. A) Dynamic. B) Sequential. C) Transient. D) Persistent. Show Answer Correct Answer: D) Persistent. 51. What method would you use to read all lines from a file into a list? A) File.getlines(). B) File.readlines(). C) File.fetch all(). D) File.read(). Show Answer Correct Answer: B) File.readlines(). 52. What is the primary function of a file handler in computer programming? A) To enhance the graphical user interface. B) To manage user inputs. C) To store the external file so that the running program can work on it. D) To display data on the screen. Show Answer Correct Answer: C) To store the external file so that the running program can work on it. 53. What is the result of trying to read a file that does not exist? A) The program continues without any issues. B) The system automatically creates a new file. C) An error is raised indicating the file does not exist. D) The file opens successfully with default content. Show Answer Correct Answer: C) An error is raised indicating the file does not exist. 54. What method is used to write multiple rows to a CSV file at once? A) Csv.insertrows(). B) Csv.writeall(). C) Csv.writerows(). D) Csv.addrows(). Show Answer Correct Answer: C) Csv.writerows(). 55. What does the 'with' statement do when handling files? A) The 'with' statement allows multiple files to be opened simultaneously. B) The 'with' statement requires manual file closure after use. C) The 'with' statement prevents file access errors. D) The 'with' statement automatically closes the file after its block of code is executed. Show Answer Correct Answer: D) The 'with' statement automatically closes the file after its block of code is executed. 56. A=m.read(3)Here the above code read(3) will point which pointer position ..... if the file content is ..... 12, welcome-1jio A) ,. B) E. C) 2. D) W. Show Answer Correct Answer: D) W. 57. What does file.write("Hello") do? A) Writes Hello to file. B) Appends Hello. C) Reads Hello from file. D) Deletes Hello. Show Answer Correct Answer: A) Writes Hello to file. 58. How do you open a file for writing in Python? A) Open('filename.txt', 'w'). B) Open('filename.txt', 'r'). C) Open('filename.txt', 'a'). D) Open('filename.txt', 'x'). Show Answer Correct Answer: A) Open('filename.txt', 'w'). 59. Which of the following file-modes does retains file data and append new data. A) 'a'. B) 'w+'. C) 'r+'. D) 'a+'. Show Answer Correct Answer: D) 'a+'. 60. To write dictionaries, tuples and any other python objects in binary file ..... function is used A) Writelines(). B) Dump(). C) Load(). D) Write(). Show Answer Correct Answer: B) Dump(). ← PreviousNext →Related QuizzesScience QuizzesClass 11 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 7Class 11 Computer Science Chapter 6 File Handling Quiz 8Class 11 Computer Science Chapter 6 File Handling Quiz 9 🏠 Back to Homepage 📘 Download PDF Books 📕 Premium PDF Books