This quiz works best with JavaScript enabled. Home > Cbse > Class 11 > Science > Computer Science > Class 11 Computer Science Chapter 6 File Handling – Quiz 8 🏠 Homepage 📘 Download PDF Books 📕 Premium PDF Books Class 11 Computer Science Chapter 6 File Handling Quiz 8 (60 MCQs) Quiz Instructions Select an option to see the correct answer instantly. 1. What does the 'WRITE' mode do when a file is opened in this mode? A) Reads data from the file. B) Writes data to the file, overwriting any existing content. C) Adds data to the end of the file. D) Reads and writes data to the file. Show Answer Correct Answer: B) Writes data to the file, overwriting any existing content. 2. What are some common exceptions that can occur during file operations in Python? A) SyntaxError. B) ValueError. C) FileNotFoundError, PermissionError, IOError, OSError. D) IndexError. Show Answer Correct Answer: C) FileNotFoundError, PermissionError, IOError, OSError. 3. Abhishek and Adivya are working on a project that involves reading data from a CSV file. They need to skip the header row to process the data correctly. How can they achieve this? A) Set skip header=True in csv.reader(). B) Use next() before iterating over rows. C) Both a and b. D) Use csv.Sniffer() to detect headers. Show Answer Correct Answer: B) Use next() before iterating over rows. 4. How can you check if a file exists at a specified path in Python? A) Verify file existence with 'file exists' method. B) Check the file using 'file check' module. C) Use the 'check file' function. D) Import osfile path = 'path/to/file'if os.path.exists(file path):print('File exists')else:print('File does not exist'). Show Answer Correct Answer: D) Import osfile path = 'path/to/file'if os.path.exists(file path):print('File exists')else:print('File does not exist'). 5. Which module in Python is used to process csv file A) Pickle. B) Random. C) CSV. D) Csv.reader(). Show Answer Correct Answer: C) CSV. 6. What is the primary purpose of file handling in Python? A) To manage memory allocation. B) To create graphical user interfaces. C) To save data for further use. D) To display data on the console. Show Answer Correct Answer: C) To save data for further use. 7. What modules can be used for binary and CSV file operations in Python? A) Pandas. B) Numpy. C) Os. D) Struct, csv. Show Answer Correct Answer: D) Struct, csv. 8. How can you handle errors in file operations in Python? A) Use try-except blocks to handle specific errors that may occur during file operations. B) Ignore errors that occur during file operations. C) Use if-else statements to handle errors in file operations. D) Handle errors by restarting the Python interpreter. Show Answer Correct Answer: A) Use try-except blocks to handle specific errors that may occur during file operations. 9. Internal translations takes place in ..... files A) Text. B) Binary. C) Csv. D) All. Show Answer Correct Answer: A) Text. 10. The ..... device able to read an error message. A) Stdout. B) Stdin. C) Stderr. D) None of this. Show Answer Correct Answer: C) Stderr. 11. Which function is used to open a file in C? A) Fopen(). B) Fileopen(). C) Open(). D) Openfile(). Show Answer Correct Answer: A) Fopen(). 12. Which module is required to use function dump()? A) Pickle. B) Flush. C) Unpickle. D) Math. Show Answer Correct Answer: A) Pickle. 13. When Reading from text files, which of the following should appear in the loop? A) READFILE. B) OPENFILE. C) DECLARE. D) READ. Show Answer Correct Answer: A) READFILE. 14. Which of the following is not a valid mode to open a text file? A) W+. B) Ab. C) R. D) R+. Show Answer Correct Answer: B) Ab. 15. What mode should be used to write to a binary file? A) Wb. B) Rb. C) Ab. D) Wbx. Show Answer Correct Answer: A) Wb. 16. The ..... function removes the given character from trailing left ends. A) Strip(). B) Lstrip(). C) Rstrip(). D) All these. Show Answer Correct Answer: B) Lstrip(). 17. How do you handle a ValueError when converting input to an integer? A) Use a try-except block to catch ValueError during conversion. B) Ignore the error and proceed with the program. C) Convert the input to a string before conversion. D) Use a for loop to iterate through the input. Show Answer Correct Answer: A) Use a try-except block to catch ValueError during conversion. 18. Which mode do you use to open a file for reading in Python? A) R. B) W. C) Wb. D) A. Show Answer Correct Answer: A) R. 19. What is the purpose of the 'open()' function in programming? A) To rename a file. B) To close a file. C) To read from or write to a file. D) To delete a file. Show Answer Correct Answer: C) To read from or write to a file. 20. Readlines() method return? A) String. B) List. C) Dictionary. D) None of the above. Show Answer Correct Answer: B) List. 21. Which of the following functions is used to write data in the binary file? A) Load(). B) Read(). C) Dump(). D) Write(). Show Answer Correct Answer: C) Dump(). 22. Which mode in fopen() allows both reading and writing to a file without truncating it? A) "r+". B) "a". C) "r". D) "w". Show Answer Correct Answer: A) "r+". 23. What does the readlines() method return when reading a text file? A) A tuple of lines. B) A dictionary of lines. C) A list of strings, each representing a line. D) A single string. Show Answer Correct Answer: C) A list of strings, each representing a line. 24. Abhishek and Taran are working on a project that requires them to save data in a CSV file. They need to write a header row to the CSV file in Python without using DictWriter. How can they achieve this? A) Use the header argument in csv.writer() while writing rows. B) Write the header manually without using any library. C) Use open() and write() methods to create the header line. D) Use csv.writer() and call writerow() with the list of headers. Show Answer Correct Answer: D) Use csv.writer() and call writerow() with the list of headers. 25. Which header file is required for using file handling functions in C? A) Math.h. B) Stdlib.h. C) String.h. D) Stdio.h. Show Answer Correct Answer: D) Stdio.h. 26. What is the purpose of the Writer function in CSV file handling? A) The purpose of the Writer function is to write data to CSV files in Python. B) Writer function is used to convert CSV files into JSON format. C) Writer function is designed to create 3D models from CSV data. D) Writer function allows for real-time visualization of CSV data. Show Answer Correct Answer: A) The purpose of the Writer function is to write data to CSV files in Python. 27. What will happen if you try to open a file that does not exist in the read mode ("r") in Python? A) The file will be opened in write mode instead. B) An error will be raised. C) The file will be opened in append mode. D) The file will be created. Show Answer Correct Answer: B) An error will be raised. 28. Jika kita ingin menambahkan data ke file tanpa menghapus isi yang ada, kita menggunakan mode apa? A) Ios::app. B) Ios::out. C) Ios::trunc. D) Ios::in. Show Answer Correct Answer: A) Ios::app. 29. What is the extension of a binary file usually used in Python? A) .exe. B) .bin. C) .txt. D) .doc. Show Answer Correct Answer: B) .bin. 30. Difference between r+ and w+ A) No difference is there. B) In w+ mode the pointer is placed at begining and in r+ the pointer is placed at end. C) In r+ mode the pointer is placed at beginning and in w+ the pointer is placed at end. D) Both pointer of the modes are placed at start and end. Show Answer Correct Answer: B) In w+ mode the pointer is placed at begining and in r+ the pointer is placed at end. 31. Which mode in Python is used to open a file for creating (and return an error if the file exists)? A) R. B) X. C) All the above. D) None of the above. Show Answer Correct Answer: B) X. 32. Write the output of the following:f=open("test.txt", "w+") f.write("File-Handling") a=f.read(5) print(a) A) File-. B) File. C) File-H. D) No Output. Show Answer Correct Answer: D) No Output. 33. Read() function keep the file pointer at ..... A) EOL. B) EOF. C) EOP. D) BOF. Show Answer Correct Answer: B) EOF. 34. What is the function of 'os.makedirs()'? A) To list all directories. B) To delete a directory. C) To create multiple directories at once. D) To create a single directory. Show Answer Correct Answer: C) To create multiple directories at once. 35. Which of the following commands canbe used to read "n" number of characters from a file using the file object ? A) File.read(n). B) N = file.read(). C) File.readlines(). D) File.readline(n). Show Answer Correct Answer: A) File.read(n). 36. What does the relpath() function return? A) The absolute path of a file. B) The relative path between two locations. C) All the above. D) None of the above. Show Answer Correct Answer: B) The relative path between two locations. 37. What does the last byte of a file contain? A) Start of the file. B) File pointer. C) End-of-file (EOF) character. D) Metadata. Show Answer Correct Answer: C) End-of-file (EOF) character. 38. What is the purpose of error handling in file operations? A) To improve performance. B) To prevent crashes. C) To manage file types. D) To enhance user experience. Show Answer Correct Answer: B) To prevent crashes. 39. What is a file in the context of programming? A) A method to display data on the console. B) A type of variable in programming. C) A temporary storage for data. D) A sequence of bytes on the disk. Show Answer Correct Answer: D) A sequence of bytes on the disk. 40. In ..... storage value of variable is not lost even though the computer is not supplied electricity A) Non volatile. B) Volatile. C) A and b. D) None. Show Answer Correct Answer: A) Non volatile. 41. What will be the output of the following code?import java.io.*; class demoFile { public static void main(String args[]) {File f = new File("C:/java/xyz"); System.out.print(f.getName()); } } A) Xyz. B) C:/java/xyz. C) Java/xyz. D) Java. Show Answer Correct Answer: A) Xyz. 42. What is the significance of working with file paths in Python file handling? A) Working with file paths in Python file handling has no impact on data management. B) File paths in Python file handling are only used for decorative purposes. C) Python file handling does not support file paths. D) File paths in Python file handling are essential for specifying the location of files on the system, enabling reading, writing, and managing data effectively. Show Answer Correct Answer: D) File paths in Python file handling are essential for specifying the location of files on the system, enabling reading, writing, and managing data effectively. 43. Describe the use of the Pickle Module in Python. A) The Pickle module in Python is used for serializing and deserializing Python objects. B) Pickle Module is used for controlling the temperature of pickles in Python. C) Pickle Module is used for generating random pickles in Python. D) The Pickle module is used for creating pickled vegetables in Python. Show Answer Correct Answer: A) The Pickle module in Python is used for serializing and deserializing Python objects. 44. ..... function returns the list of strings. A) Read(). B) Readline(). C) Readlines(). D) None of the above. Show Answer Correct Answer: C) Readlines(). 45. Arrays are often used to hold data read from files. A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: A) True. 46. How do you open a file for reading in Python? A) Use 'read('filename.txt')'. B) Use 'open('filename.txt', 'r')'. C) Use 'load('filename.txt')' to read. D) Open with 'open('filename.txt', 'w')'. Show Answer Correct Answer: B) Use 'open('filename.txt', 'r')'. 47. To open a file in text mode, which character is used? A) 't'. B) 'x'. C) 'b'. D) None. Show Answer Correct Answer: A) 't'. 48. What is the function "a" in file handling A) Read. B) Write. C) Append. D) None of the above. Show Answer Correct Answer: C) Append. 49. What is the purpose of the readlines() function? A) To read all lines from a file and return them as a list. B) To read a single line from a file. C) To write all lines to a file. D) To count the number of lines in a file. Show Answer Correct Answer: A) To read all lines from a file and return them as a list. 50. Apa yang harus dilakukan setelah menulis ke file untuk memastikan data tersimpan dengan benar? A) Menutup file dengan close(). B) Menghapus file yang sudah ada. C) Mengubah nama file. D) Menyalin file ke lokasi lain. Show Answer Correct Answer: A) Menutup file dengan close(). 51. File Object is also Known as A) File handle. B) File window. C) File Modes. D) All these. Show Answer Correct Answer: A) File handle. 52. Used to get data from datafile and send output into datafile. A) Files. B) File processing. C) Data files. D) File handling. Show Answer Correct Answer: D) File handling. 53. Which of the following is used to separate a line into words. A) Linestowords(). B) Words(). C) Separate(). D) Split(). Show Answer Correct Answer: D) Split(). 54. What is the difference between 'rb' and 'wb' file modes? A) Both 'rb' and 'wb' are used for reading files, but in different formats. B) 'rb' is for writing text files, and 'wb' is for reading text files. C) The difference is that 'rb' is for reading binary files, and 'wb' is for writing binary files. D) 'rb' is for reading files in ASCII format, while 'wb' is for writing in UTF-8. Show Answer Correct Answer: C) The difference is that 'rb' is for reading binary files, and 'wb' is for writing binary files. 55. Which method is used to write data to a csv file using the csv module in Python? A) Writecsv(). B) Csv.append. C) Csv.write. D) Appendcsv(). Show Answer Correct Answer: C) Csv.write. 56. What is the meant by 'a' in the following operation?fp = fopen("letsfindcourse.txt", "a"); A) Append. B) Apprehend. C) Add. D) Attach. Show Answer Correct Answer: A) Append. 57. How does the operating system manage memory allocation? A) The operating system uses hardware to manage memory allocation. B) The operating system relies on external devices for memory management. C) The operating system allocates memory using techniques like segmentation, paging, and virtual memory management. D) Memory allocation is handled solely by user applications. Show Answer Correct Answer: C) The operating system allocates memory using techniques like segmentation, paging, and virtual memory management. 58. 1 Which of the following command is used to open a file "temp.dat" in read-mode only? A) Infile = open( "temp.dat" , "rb" ). B) Infile = open(file = "temp.dat" , "r+" ). C) Infile = open( "temp.dat" , "r" ). D) Infile = open(file = "temp.dat" , "rb" ). Show Answer Correct Answer: A) Infile = open( "temp.dat" , "rb" ). 59. A binary file stores the information in the form of ..... A) Bytes. B) Stream of Bytes. C) 0's and 1's. D) .txt. Show Answer Correct Answer: B) Stream of Bytes. 60. What is the purpose of the 'F dot read' command in the Python file handling examples? A) To write data to the file. B) To read a line from the file. C) To close the file. D) To open the file for reading. Show Answer Correct Answer: B) To read a line from the file. ← 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 9 🏠 Back to Homepage 📘 Download PDF Books 📕 Premium PDF Books