This quiz works best with JavaScript enabled. Home > Cbse > Class 11 > Science > Computer Science > Class 11 Computer Science Chapter 6 File Handling – Quiz 2 🏠 Homepage 📘 Download PDF Books 📕 Premium PDF Books Class 11 Computer Science Chapter 6 File Handling Quiz 2 (60 MCQs) Quiz Instructions Select an option to see the correct answer instantly. 1. Which class in Java is used for file handling? A) FileReader. B) BufferedReader. C) File. D) Scanner. Show Answer Correct Answer: C) File. 2. Fflush(NULL) flushes all ..... A) Input streams. B) Output streams. C) Appended text. D) Previous contents. Show Answer Correct Answer: B) Output streams. 3. In file handling, what do the terms "r" and "a" stand for? A) Read, append. B) Append, read. C) Write, append. D) None of these. Show Answer Correct Answer: A) Read, append. 4. What is the purpose of a module in Python? A) To define a function. B) To group related functions and variables into a file. C) To execute Python scripts automatically. D) To document Python code. Show Answer Correct Answer: B) To group related functions and variables into a file. 5. Which mode is used to open a file for appending in Python? A) 'r'. B) 'x'. C) 'a'. D) 'w'. Show Answer Correct Answer: C) 'a'. 6. ..... class provides the capability to read primitive data types from an input stream. A) DataInputStream. B) PushbackInputStream. C) BufferedInputStream. D) PipeInputStream. Show Answer Correct Answer: A) DataInputStream. 7. Best way to calculate total from numeric column in CSV? A) Add directly as strings. B) Count commas. C) Int(row["Column"]) inside loop. D) Use .split(", ") always. Show Answer Correct Answer: C) Int(row["Column"]) inside loop. 8. What are the different types of function arguments in Python? A) Immutable arguments. B) Named arguments only. C) Positional arguments, keyword arguments, default arguments, variable-length arguments (*args, **kwargs), keyword-only arguments. D) Static arguments. Show Answer Correct Answer: C) Positional arguments, keyword arguments, default arguments, variable-length arguments (*args, **kwargs), keyword-only arguments. 9. Which method writes multiple lines to a file? A) Writeline(). B) Writeall(). C) Writelines(). D) Multiline(). Show Answer Correct Answer: C) Writelines(). 10. What is the purpose of the 'open' function in Python? A) To close a file after reading or writing. B) To open a file and return a file object for reading or writing. C) To create a new file in the current directory. D) To delete a file from the system. Show Answer Correct Answer: B) To open a file and return a file object for reading or writing. 11. Which function is used to close a file in C++ after performing file operations? A) 'closefile()'. B) 'close()'. C) 'exit()'. D) 'end()'. Show Answer Correct Answer: B) 'close()'. 12. This mode will open file with read write purpose A) W+. B) W. C) R. D) R+. Show Answer Correct Answer: D) R+. 13. Which of the following is NOT a basic operation on files? A) Opening a file. B) Reading a file. C) Closing a file. D) Renaming a file. Show Answer Correct Answer: D) Renaming a file. 14. Apa yang akan ditampilkan jika fwrite berhasil menulis data ke file? A) Data yang ditulis. B) Tidak ada output. C) ID file. D) Pesan kesalahan. Show Answer Correct Answer: A) Data yang ditulis. 15. What does feof() check for? A) Checks for end of file. B) Writes data to a file. C) Opens a file. D) Checks for file errors. Show Answer Correct Answer: A) Checks for end of file. 16. While writing data to file using ..... mode, the previous content of existing file will be overwritten and new content will be saved. A) W. B) R. C) A. D) None. Show Answer Correct Answer: A) W. 17. What is a relative path? A) A path that specifies the location of a file relative to the current directory. B) A relative path is a URL that points to a web resource. C) A relative path is a method of organizing files in a database. D) A relative path is the absolute location of a file on the system. Show Answer Correct Answer: A) A path that specifies the location of a file relative to the current directory. 18. What is the need for data files in Python? A) To store data in RAM. B) To permanently store data for future use. C) To erase data when the program is over. D) To handle small amount of data. Show Answer Correct Answer: B) To permanently store data for future use. 19. Which of the following is NOT a characteristic of a user-defined function? A) It can be reused in the program. B) It is defined by the user. C) It is automatically available in all programs. D) It can take parameters. Show Answer Correct Answer: C) It is automatically available in all programs. 20. Return type of which of the following methods is list A) Writeline. B) Flush. C) Writelines. D) Readline. Show Answer Correct Answer: C) Writelines. 21. Select the most appropriate format of seek () A) .seek():. B) .seek():. C) seek():. D) .seek(). Show Answer Correct Answer: D) .seek(). 22. Which Tkinter widget allows users to select multiple options? A) Radiobuttons. B) Dialogs. C) Sliders. D) Checkboxes. Show Answer Correct Answer: D) Checkboxes. 23. Select the statement to open a file named MYDATA.dat in read binary 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: A) Myfile=open("MYDATA.dat", "rb"). 24. Fungsi mana yang digunakan untuk membaca data dari file biner? A) Fprintf. B) Fscanf. C) Fwrite. D) Fread. Show Answer Correct Answer: D) Fread. 25. Function returns the current position of file pointer in the file A) Read(). B) Tell(). C) Flush(). D) Seek(). Show Answer Correct Answer: B) Tell(). 26. What will the following code output if data.dat contains a pickled dictionary {'A':1, 'B':2}? import pickle with open('data.dat', 'rb') as f:data = pickle.load(f) print(data['A']) A) Error. B) 1. C) 2. D) {'A':1, 'B':2}. Show Answer Correct Answer: B) 1. 27. What happens if you open a file in 'write' mode? A) The file becomes read-only. B) You can add more content. C) You can only read the file. D) The current content is deleted. Show Answer Correct Answer: D) The current content is deleted. 28. Which of the following is not a valid mode to open a file? A) Ab. B) R+. C) Rw. D) W+. Show Answer Correct Answer: C) Rw. 29. What are the different modes in which you can open a file in Python? A) B. B) 'r', 'w', 'a', 'r+', 'w+', 'a+'. C) Z. D) X. Show Answer Correct Answer: B) 'r', 'w', 'a', 'r+', 'w+', 'a+'. 30. ..... and ..... statements are used to prevent an exception from terminating a program A) Try, except,. B) Try, else. C) Try. D) Try, catch. Show Answer Correct Answer: A) Try, except,. 31. What is the method to read a file line by line in Python? A) Use 'file.read()' to read the entire file at once. B) Use 'open(filename).readlines()' to read a file line by line. C) Use 'for line in read(filename):' to read a file line by line. D) Use 'with open(filename) as file:for line in file:' to read a file line by line. Show Answer Correct Answer: D) Use 'with open(filename) as file:for line in file:' to read a file line by line. 32. Which mode(s) will error if the file is not found when trying to open() it? A) Read. B) Write. C) Append. D) All of them. Show Answer Correct Answer: A) Read. 33. Which method is used to check if a file is writable? A) Write(). B) CanRead(). C) CanWrite(). D) IsWritable(). Show Answer Correct Answer: C) CanWrite(). 34. Which method is used to close an opened file in Python? A) File.close(). B) File.closeFile(). C) Close(file). D) File.end(). Show Answer Correct Answer: A) File.close(). 35. Where files are stored permanently? A) RAM. B) Hard Disk. C) Cache memory. D) None of these. Show Answer Correct Answer: B) Hard Disk. 36. Is it possible to create a text file in python? A) Yes. B) No. C) Machine dependent. D) All of the mentioned. Show Answer Correct Answer: A) Yes. 37. Information stored on a storage device with a specific name is called a ..... A) Dictionary. B) Array. C) File. D) Tuple. Show Answer Correct Answer: C) File. 38. What is the method used to read a specific number of bytes from a file in Python? A) Read(n). B) Readlines(). C) Readline(). D) Readall(). Show Answer Correct Answer: A) Read(n). 39. What method would you use to append data to an existing file? A) Use 'open(file, 'r')' in Python. B) Use 'open(file, 'w+')' in Python. C) Use 'open(file, 'x')' in Python. D) Use 'open(file, 'a')' in Python. Show Answer Correct Answer: D) Use 'open(file, 'a')' in Python. 40. Which mode would you use to append data to a text file? A) D. B) C. C) B. D) A. Show Answer Correct Answer: D) A. 41. How can you use the tell() and seek() methods in Python file handling? A) Tell() and seek() are used for handling exceptions in Python file operations. B) You can use tell() to write data to a file and seek() to read data from a file. C) You can use tell() to get the current position and seek() to move to a specific position in Python file handling. D) Tell() returns the size of the file and seek() is used to close the file in Python. Show Answer Correct Answer: C) You can use tell() to get the current position and seek() to move to a specific position in Python file handling. 42. In file handling, what does EOF stand for, and why is it significant? A) End Of File, it indicates that there is no more data to read from the file. B) Execution Of File, it indicates that the file is currently being executed. C) Each Open File, a reference to all open files in a program. D) Error On File, an error message that occurs when a file cannot be accessed. Show Answer Correct Answer: A) End Of File, it indicates that there is no more data to read from the file. 43. How can you append data to an existing file in Python? A) Use open('filename', 'x') to create a new file. B) Use open('filename', 'a') to append data to an existing file. C) Use open('filename', 'r') to read data from a file. D) Use open('filename', 'w') to overwrite the file. Show Answer Correct Answer: B) Use open('filename', 'a') to append data to an existing file. 44. A binary file has 5 records stored using pickle.dump(). Which error occurs if you try pickle.load() after last record? A) IndexError. B) EOFError. C) KeyError. D) ValueError. Show Answer Correct Answer: B) EOFError. 45. LOCK ..... EX stands for A) Extended lock. B) Exclusive lock. C) Extrapolar lock. D) Excess lock. Show Answer Correct Answer: B) Exclusive lock. 46. Pada akhir presentasi, kata apa yang muncul di layar? A) Sekian sebagai penutup. B) Error sebagai peringatan. C) Mulai sebagai pembuka. D) Halo sebagai salam. Show Answer Correct Answer: A) Sekian sebagai penutup. 47. In a binary file 'wb' mode is equal to ..... A) Read and write. B) Append only. C) Read only. D) Write only. Show Answer Correct Answer: D) Write only. 48. What does the 'R' parameter signify in the 'open' command when opening a file in Python? A) Run the file. B) Replace the file. C) Read the file. D) Remove the file. Show Answer Correct Answer: C) Read the file. 49. Taran is working on a project that involves reading and writing CSV files. He comes across the newline=" argument in the open() function. What does this argument do when working with CSV files? A) It specifies the encoding type for the CSV file. B) It adds extra newline characters when reading CSV files. C) It prevents the addition of extra newline characters when reading or writing CSV files. D) It determines the delimiter used in the CSV file. Show Answer Correct Answer: C) It prevents the addition of extra newline characters when reading or writing CSV files. 50. What does with open( ..... ) as f:ensure? A) File stays open. B) Deletes file. C) Creates backup. D) File auto-closes. Show Answer Correct Answer: D) File auto-closes. 51. Which one of the following is correct syntax for opening a file. A) FILE fopen(const filename, const char *mode). B) FILE fopen(const filename). C) FILE open(const*filename). D) FILE open(const filename, const char *mode). Show Answer Correct Answer: A) FILE fopen(const filename, const char *mode). 52. Which of the following mode is applied while writing into the file? A) 'read'. B) 'r'. C) 'w'. D) 'write'. Show Answer Correct Answer: C) 'w'. 53. Which library is used for CSV handling in Python? A) Csv. B) Pickle. C) Json. D) Pandas only. Show Answer Correct Answer: A) Csv. 54. In the below statement myfile is called ..... myfile=open("school.txt") A) Filename. B) File path. C) File handle. D) Both (b) and (c). Show Answer Correct Answer: C) File handle. 55. What is the purpose of the APPEND mode in file handling? A) To overwrite existing data in the file. B) To delete the file after writing data. C) To read data from the file. D) To add new data to the end of the file without deleting existing data. Show Answer Correct Answer: D) To add new data to the end of the file without deleting existing data. 56. Apa yang digunakan untuk membaca baris demi baris dari file? A) Fputs. B) Fgets. C) Fprintf. D) Fwrite. Show Answer Correct Answer: B) Fgets. 57. What will be the output of the following Python codeprint(4 + '3') A) TypeError. B) NameError. C) IndexError. D) ValueError. Show Answer Correct Answer: A) TypeError. 58. Which method rolls back the present transaction? A) Rollback(). B) Commit(). C) Undo(). D) Back(). Show Answer Correct Answer: A) Rollback(). 59. What will happen if an exception is raised in a 'try' block but no 'except' block is provided? A) The program will terminate. B) No issues. It will continue with a default exception. C) Exception is ignored. D) It raises and error. Show Answer Correct Answer: D) It raises and error. 60. How can you read a specific number of bytes from a file? A) Invoke file.read(n, m) to read 'n' bytes with a buffer size of 'm'. B) Call file.readBytes(n) to access 'n' bytes from a file. C) Use file.get(n) to retrieve 'n' bytes from a file. D) Use file.read(n) to read 'n' bytes from a file. Show Answer Correct Answer: D) Use file.read(n) to read 'n' bytes from a file. ← PreviousNext →Related QuizzesScience QuizzesClass 11 QuizzesClass 11 Computer Science Chapter 6 File Handling Quiz 1Class 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 9 🏠 Back to Homepage 📘 Download PDF Books 📕 Premium PDF Books