This quiz works best with JavaScript enabled. Home > Cbse > Class 11 > Science > Computer Science > Class 11 Computer Science Chapter 6 File Handling – Quiz 19 🏠 Homepage 📘 Download PDF Books 📕 Premium PDF Books Class 11 Computer Science Chapter 6 File Handling Quiz 19 (60 MCQs) Quiz Instructions Select an option to see the correct answer instantly. 1. What happens when file opened in 'a' mode? A) New data added at the end. B) Content is erased. C) Content is overwritten. D) File is deleted. Show Answer Correct Answer: A) New data added at the end. 2. What will the following code snippet do?F=open("abc.txt", "a")x="class12"F.write(x)F.close() A) Reading from the file by erasing old content. B) Reading from the file without erasing old content. C) Writing into the file by erasing old content. D) Writing into the file without erasing old content. Show Answer Correct Answer: D) Writing into the file without erasing old content. 3. What happens when '1' == 1 is executed? A) An TypeError occurs. B) A ValueError occurs. C) We get a False. D) We get a True. Show Answer Correct Answer: C) We get a False. 4. Public class Foo { public static void main(String[] args) { try { return; } finally { System.out.println( "Finally" ); } } } A) Finally. B) Compilation fails. C) The code runs with no output. D) An exception is thrown at runtime. Show Answer Correct Answer: A) Finally. 5. Which exception is handled while reading binary file? A) FileNotFoundError. B) EOFError. C) OSError. D) All of these. Show Answer Correct Answer: D) All of these. 6. We can create our own error types in Python? A) Yes, we can create our error types in Python. B) No, we cannot define custom errors in Python. C) All the above. D) None of the above. Show Answer Correct Answer: A) Yes, we can create our error types in Python. 7. What is the correct order of operations for reading from a file in pseudocode? A) Close $\rightarrow$ Open $\rightarrow$ Read. B) Read $\rightarrow$ Open $\rightarrow$ Close. C) Open $\rightarrow$ Close $\rightarrow$ Read. D) Open $\rightarrow$ Read $\rightarrow$ Close. Show Answer Correct Answer: D) Open $\rightarrow$ Read $\rightarrow$ Close. 8. It is necessary to always create the file in the same default folder where Python has been installed. A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: B) False. 9. How can you check if a file exists before deleting it? A) Using os.remove() function. B) Using os.path.exists() function. C) Using close() function. D) Using open() function. Show Answer Correct Answer: B) Using os.path.exists() function. 10. The full name of a file is also called ..... A) Path name. B) Relative Path Name. C) Directory. D) Absolute path Name. Show Answer Correct Answer: A) Path name. 11. ..... function will break the link of file object and file on the disk A) Open(). B) Read(). C) Close(). D) Write(). Show Answer Correct Answer: D) Write(). 12. How do you handle exceptions in Python while working with files? A) Always ignore exceptions when working with files. B) Close the file before handling exceptions. C) Use print statements to debug file operations. D) Use try-except blocks to catch exceptions during file operations. Show Answer Correct Answer: D) Use try-except blocks to catch exceptions during file operations. 13. Which class can be used to read data line by line using readLine() method? A) BufferedReader. B) DataInputStream. C) DataOutputtream. D) InputStreamReader. Show Answer Correct Answer: A) BufferedReader. 14. Can values got from forms in html be given to php A) Sometimes. B) Yes. C) No. D) None. Show Answer Correct Answer: B) Yes. 15. Which Tkinter widget is used to create clickable elements for user interaction? A) Label. B) Sliders. C) Canvas Widget. D) Buttons. Show Answer Correct Answer: D) Buttons. 16. What will be the output of add ..... two(5, 7)? A) 12. B) 2. C) 35. D) None. Show Answer Correct Answer: A) 12. 17. The correct syntax of seek() is: A) Seek.file object(offset). B) Seek(offset [, reference point]). C) Seek(offset, file object). D) File object.seek(offset [, reference point]). Show Answer Correct Answer: D) File object.seek(offset [, reference point]). 18. How do you close a file after opening it? A) Call the 'terminate' function on the file handle. B) Use the 'close' method on the file object. C) Use the 'delete' method on the file object. D) Invoke the 'end' command on the file stream. Show Answer Correct Answer: B) Use the 'close' method on the file object. 19. Which function is used to check the file opening mode of the file? A) Readable(). B) Writable(). C) Both readable() & writable(). D) None. Show Answer Correct Answer: C) Both readable() & writable(). 20. Which method reads a single line from a file in Python? A) File.read(). B) File.readchar(). C) File.readlines(). D) File.readline(). Show Answer Correct Answer: D) File.readline(). 21. In CSV files, what does each row represent? A) Each row represents a header. B) Each row represents a paragraph. C) Each row represents a single record or data entry. D) Each row represents a column. Show Answer Correct Answer: C) Each row represents a single record or data entry. 22. CSV file differs from binary file because: A) CSV is human-readable. B) CSV cannot be imported into Excel. C) CSV stores Python objects directly. D) CSV always takes less memory. Show Answer Correct Answer: A) CSV is human-readable. 23. When will the else part of try-except-else be executed? A) When an exception occurs in to except block. B) When no exception occurs. C) When an exception occurs. D) Always. Show Answer Correct Answer: B) When no exception occurs. 24. File formats are specified in the file extension A) TRUE. B) FALSE. C) All the above. D) None of the above. Show Answer Correct Answer: A) TRUE. 25. What exception does the createNewFile() method throw if an error occurs? A) IOException. B) FileNotFoundException. C) NullPointerException. D) FileAlreadyExistsException. Show Answer Correct Answer: A) IOException. 26. If you will have to store roll numbers of all the students, then which python datatype will you use? A) List. B) Set. C) Tuple. D) Dictionary. Show Answer Correct Answer: B) Set. 27. Which function is used to read records from a binary file? A) Pickle.open(). B) Pickle.read(). C) Pickle.load(f). D) Pickle.dump(l, f). Show Answer Correct Answer: C) Pickle.load(f). 28. What does the 'os.listdir()' function return? A) A list of all files in a directory. B) The size of a directory. C) The absolute path of a file. D) The current working directory. Show Answer Correct Answer: A) A list of all files in a directory. 29. What does the 'A' parameter do when opening a file? A) Creates a new file. B) Clears the file before writing. C) Appends to the end of the file. D) Opens the file in read-only mode. Show Answer Correct Answer: C) Appends to the end of the file. 30. Which command is used to open the file for read only A) Outfile = openReadWrite("temp.txt"). B) Outfile = openWrite("temp.txt"). C) Outfile = openRead("temp.txt"). D) None of them would do it. Show Answer Correct Answer: C) Outfile = openRead("temp.txt"). 31. Why is it important to close a file after performing file I/O operations? A) To delete the file from the computer. B) To protect the file from viruses. C) To free up resources tied with the file. D) To prevent others from accessing the file. Show Answer Correct Answer: C) To free up resources tied with the file. 32. There is only one way to read a file in python. A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: B) False. 33. What does the following code do?f=open("test.txt") A) Opens the file in WRITE mode. B) Opens the file in READ mode. C) Opens the file both READING and WRITING. D) Syntax Error. E) None of the choices. Show Answer Correct Answer: B) Opens the file in READ mode. 34. What will the following code do?with open('file.txt', 'w') as f:f.write('Hello, world!') A) Create or open 'file.txt' and write 'Hello, world!' to it. B) Open 'file.txt' for reading and print 'Hello, world!'. C) Create 'file.txt' if it doesn't exist and write 'Hello, world!' to it. D) None of the above. Show Answer Correct Answer: A) Create or open 'file.txt' and write 'Hello, world!' to it. 35. What does the 'ungetc()' function in C do? A) Writes a character to a file. B) Pushes a character back onto the input stream. C) Reads a character from a file. D) Closes a file. Show Answer Correct Answer: B) Pushes a character back onto the input stream. 36. What does Filehandle.writelines (L) function do A) Writes all string in list L as lines to file refrence by filehandle. B) Reads all string in list L as lines to file refrence by file handle. C) Writes and reads. D) None. Show Answer Correct Answer: A) Writes all string in list L as lines to file refrence by filehandle. 37. In the data hierarchy, which of the choices contains multiple records? A) File. B) Bits. C) Records. D) Characters. Show Answer Correct Answer: A) File. 38. What does the 'eof' function check in file operations? A) Whether the end of the file has been reached. B) Whether the file is empty. C) Whether the file is writable. D) Whether the file is open. Show Answer Correct Answer: A) Whether the end of the file has been reached. 39. Which statement will return one line from a file (file object is 'f')? A) F.readlines(). B) F.read(). C) F.readline(). D) F.line. Show Answer Correct Answer: C) F.readline(). 40. The ..... device read from the keyboard. A) Stdout. B) Stdin. C) Stderr. D) None of this. Show Answer Correct Answer: B) Stdin. 41. What is the difference between 'read()' and 'readlines()' methods? A) 'read()' returns a list of strings, and 'readlines()' returns a single string. B) 'read()' reads a file line by line, while 'readlines()' reads the entire file at once. C) The difference is that 'read()' returns a single string, and 'readlines()' returns a list of strings. D) 'read()' is used for binary files, while 'readlines()' is used for text files. Show Answer Correct Answer: C) The difference is that 'read()' returns a single string, and 'readlines()' returns a list of strings. 42. Load function of pickle module is used to A) Read data from file. B) Pickle module does not have a function load. C) Append data in the file. D) Write data in the file. Show Answer Correct Answer: A) Read data from file. 43. What method is used to read all lines from a text file? A) File.getlines(). B) File.readlines(). C) File.fetch lines(). D) File.read(). Show Answer Correct Answer: B) File.readlines(). 44. What is a binary file in Python? A) A binary file in Python is a file that only contains images. B) A binary file is a text file that can be read by humans. C) A binary file in Python is a file that contains data in a non-human-readable format, accessed in binary mode. D) A binary file is a file that stores data in a format that is always human-readable. Show Answer Correct Answer: C) A binary file in Python is a file that contains data in a non-human-readable format, accessed in binary mode. 45. Which function is used to read all lines from a text file into a list? A) Readline(). B) Write(). C) Readlines(). D) Read(). Show Answer Correct Answer: C) Readlines(). 46. The contents of a csv file "sample.csv" are shown below:sno, name, age1, Amit, 122, Harsh, 133, Vivek, 21 A) An error will be raised in Python. B) It cannot be opened in a text editor a sit is a CSV file. C) It can be treated as a text file. D) It cannot be treated as a text file as it is a CSV file. Show Answer Correct Answer: C) It can be treated as a text file. 47. What is the standard input stream in Python? A) Stdin. B) Stderr. C) Stdout. D) Input(). Show Answer Correct Answer: A) Stdin. 48. What is the first index of an array? A) 2. B) 3. C) 0. D) 1. Show Answer Correct Answer: C) 0. 49. What is the advantage of using CSV files? A) CSV files are faster to handle and smaller in size. B) CSV files can store complex data structures. C) CSV files are encrypted for security. D) CSV files can only be read by specific applications. Show Answer Correct Answer: A) CSV files are faster to handle and smaller in size. 50. Which operator is used in python to import all modules from package A) Operator. B) + operator. C) $\rightarrow$ operator. D) Operator. Show Answer Correct Answer: A) Operator. 51. Which method is used to close a file in Python? A) Write(). B) Open(). C) Seek(). D) Close(). Show Answer Correct Answer: D) Close(). 52. Which of the following function do you use to write data in the binary file? A) Send. B) Dump. C) Output. D) Write. Show Answer Correct Answer: B) Dump. 53. Which method is used to delete a file in Python? A) Os.rmdir(). B) Os.delete(). C) Os.remove(). D) Os.clear(). Show Answer Correct Answer: C) Os.remove(). 54. Which one of the following methods is responsible for sending the query to the database? A) Query(). B) Send query(). C) Query send(). D) None. Show Answer Correct Answer: A) Query(). 55. How do you delete a file in Python? A) Invoke 'remove.file(file path)' to delete a file. B) Call 'os.unlink(file path)' to erase a file. C) Use 'file.delete(file path)' to remove a file. D) Use 'os.remove(file path)' to delete a file. Show Answer Correct Answer: D) Use 'os.remove(file path)' to delete a file. 56. Rashil is working on a project that involves analyzing sales data stored in a CSV file. Which Python module should he primarily use for handling these CSV files? A) Csv. B) Txt. C) Json. D) Xml. Show Answer Correct Answer: A) Csv. 57. How do you properly close a file after performing operations on it in Python? A) File.end(). B) File.shutdown(). C) File.stop(). D) File.close(). Show Answer Correct Answer: D) File.close(). 58. 6 What is the last action that must be performed while working with the files? A) Save(). B) End(). C) Close(). D) Write(). Show Answer Correct Answer: C) Close(). 59. How can you check if a file exists before trying to open it? A) Use 'file.exists(file path)' in Python to check if a file exists. B) Check the file size to determine if it exists. C) Attempt to open the file and catch any errors. D) Use 'os.path.exists(file path)' in Python to check if a file exists. Show Answer Correct Answer: D) Use 'os.path.exists(file path)' in Python to check if a file exists. 60. Existing data is kept intact when append is use to write to a file A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: A) True. ← 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 6Class 11 Computer Science Chapter 6 File Handling Quiz 7Class 11 Computer Science Chapter 6 File Handling Quiz 8 🏠 Back to Homepage 📘 Download PDF Books 📕 Premium PDF Books