This quiz works best with JavaScript enabled. Home > Class 11 > Class 11 Computer Science Chapter 6 File Handling – Quiz 10 🏠 Homepage 📘 Download PDF Books 📕 Premium PDF Books Class 11 Computer Science Chapter 6 File Handling Quiz 10 (25 MCQs) Quiz Instructions Select an option to see the correct answer instantly. 1. What exception is raised when trying to open a file in write mode that already exists? A) FileExistsError. B) IOError. C) ValueError. D) TypeError. Show Answer Correct Answer: A) FileExistsError. 2. If you open a file in 'append' mode, what can you do? A) Add new content at the end. B) Delete the content. C) Read the file only. D) Overwrite everything in the file. Show Answer Correct Answer: A) Add new content at the end. 3. Apa yang terjadi jika file yang dibuka dengan mode "w" sudah ada? A) Data akan ditambahkan di akhir file. B) File akan dihapus dan dibuat baru. C) File tidak dapat dibuka. D) Data akan dibaca dari file. Show Answer Correct Answer: B) File akan dihapus dan dibuat baru. 4. Which mode is used to open an existing file for both reading and writing? A) "w". B) "w+". C) "r+". D) "a+". Show Answer Correct Answer: C) "r+". 5. Function readline() and readlines() are both the same functions. Is the statement True or False A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: B) False. 6. During a class project, Shaurya needs to write a single row of data to a CSV file using the csv.writer method. Which method should he use? A) Writerow(). B) Insert row(). C) Addrow(). D) Writerows(). Show Answer Correct Answer: A) Writerow(). 7. Which of the following statements correctly explain the function of seek() method? A) Tell the current position within the file. B) Indicate that the next read or write occurs from that position in a file. C) Determine if you can move the file position or not. D) Move the current file position to a different location at a defined offset. Show Answer Correct Answer: D) Move the current file position to a different location at a defined offset. 8. How many number of text file are available in Python ..... A) 1. B) 2. C) 3. D) 4. Show Answer Correct Answer: B) 2. 9. What does the "w" mode do when opening a file? A) Opens the file for reading only. B) Opens the file for writing only. C) Opens the file for appending; any data written to the file is automatically added to the end. D) Opens the file in binary write mode. Show Answer Correct Answer: B) Opens the file for writing only. 10. What is the correct way to close a file in C++? A) CloseFile(). B) Fclose(). C) FileClose(). D) Close(). Show Answer Correct Answer: D) Close(). 11. What is the purpose of the 'pprint.pformat()' function? A) To pretty print data to the console. B) To serialize data. C) To format data as a string for saving. D) To read data from a file. Show Answer Correct Answer: C) To format data as a string for saving. 12. What is the purpose of saving data before closing a program? A) To delete temporary files. B) To update the program's code. C) To prevent data loss. D) To refresh the program. Show Answer Correct Answer: C) To prevent data loss. 13. Which of the following is an example of a recursive function? A) Def factorial(n):if n == 0:return 1else:return n * factorial(n-1). B) Def print numbers(n):for i in range(1, n+1):print(i). C) Def power(x, n):result = 1for i in range(n):result *= xreturn result. D) Def sum numbers(n):sum = 0for i in range(1, n+1):sum += ireturn sum. Show Answer Correct Answer: A) Def factorial(n):if n == 0:return 1else:return n * factorial(n-1). 14. Which method is used to read the entire contents of a file as a string in Python? A) Read(). B) Readline(). C) Readlines(). D) Readfile(). Show Answer Correct Answer: A) Read(). 15. 3 Which module is used to work with binary files? A) CSV module. B) Pickle module. C) Math module. D) Binary module. Show Answer Correct Answer: B) Pickle module. 16. How do you write data to a CSV file in Python? A) Use the 'json' module to write data to a CSV file. B) Use the 'pickle' module to serialize data into a CSV format. C) Use the 'csv' module to write data to a CSV file by creating a writer object and using 'writerow()' or 'writerows()' methods. D) Write data to a CSV file using the 'open' function only. Show Answer Correct Answer: C) Use the 'csv' module to write data to a CSV file by creating a writer object and using 'writerow()' or 'writerows()' methods. 17. How can you open a text file in read mode in Python? A) Open('file.txt', 'r'). B) Open('file.txt', 'w'). C) Open('file.txt', 'x'). D) Open('file.txt', 'a'). Show Answer Correct Answer: A) Open('file.txt', 'r'). 18. To count the number of words in a text file, the best approach is: A) Count spaces. B) Use .split() on each line. C) Use .count(" "). D) Count characters. Show Answer Correct Answer: B) Use .split() on each line. 19. Afif uses fopen("log.txt", "w") to open a file and writes a log message. What will happen if log.txt already has old data inside? A) New data will be added below old data. B) Old data will be kept, new data added at top. C) Old data will be deleted and replaced with new data. D) Nothing will happen because the file is in read mode. Show Answer Correct Answer: C) Old data will be deleted and replaced with new data. 20. What is the output of the program that writes to a file? A) Data written to file successfully. B) Error opening file. C) File not found. D) Data read from file. Show Answer Correct Answer: A) Data written to file successfully. 21. Which of the following function returns a list datatype A) D=f.read(). B) D=f.read(10). C) D=f.readline(). D) D=f.readlines(). Show Answer Correct Answer: D) D=f.readlines(). 22. Which mode should you use to open a file for writing in text mode, creating it if it doesn't exist? A) "r". B) "w". C) "t". D) "b". Show Answer Correct Answer: B) "w". 23. If you open a file in 'r' mode and it does not exist, what happens? A) Creates file. B) Returns None. C) Raises error. D) Skips line. Show Answer Correct Answer: C) Raises error. 24. Mode apa yang digunakan untuk menulis ke file baru dalam fopen? A) "r". B) "a". C) "w". D) "rb". Show Answer Correct Answer: C) "w". 25. How can you create a new file if it does not exist when opening it? A) Use 'open("filename.txt", "b")' for binary mode. B) Use 'open("filename.txt", "w")' or 'open("filename.txt", "a")' in Python. C) Use 'open("filename.txt", "r")' to read the file. D) Use 'open("filename.txt", "x")' to create a new file. Show Answer Correct Answer: B) Use 'open("filename.txt", "w")' or 'open("filename.txt", "a")' in Python. ← 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 11 🏠 Back to Homepage 📘 Download PDF Books 📕 Premium PDF Books