This quiz works best with JavaScript enabled. Home > Cbse > Class 11 > Science > Computer Science > Class 11 Computer Science Chapter 6 File Handling – Quiz 4 🏠 Homepage 📘 Download PDF Books 📕 Premium PDF Books Class 11 Computer Science Chapter 6 File Handling Quiz 4 (60 MCQs) Quiz Instructions Select an option to see the correct answer instantly. 1. What is the purpose of the 'flush' method in file handling? A) The 'flush' method reads data from the file into memory. B) The 'flush' method deletes all data from the file. C) The 'flush' method ensures that all buffered data is written to the file. D) The 'flush' method closes the file after writing. Show Answer Correct Answer: C) The 'flush' method ensures that all buffered data is written to the file. 2. Why is it important to close a file after writing to it? A) To save memory. B) To avoid file corruption. C) To delete the file. D) To prevent the operating system from thinking the file is still open. Show Answer Correct Answer: D) To prevent the operating system from thinking the file is still open. 3. What is the correct declaration? A) Struct {int a}; s;. B) Struct s {int a}; s;. C) Struct s{int a};. D) All valid. Show Answer Correct Answer: D) All valid. 4. The readlines() method returns A) A list of single charecters. B) Str. C) A list of integers. D) A list of lines. Show Answer Correct Answer: D) A list of lines. 5. What is the last action that must be performed on a file? A) Save. B) Close. C) End. D) Write. Show Answer Correct Answer: B) Close. 6. What is the purpose of the with statement when working with files in Python? A) It ensures that the file is closed after its block of code is executed. B) It allows multiple files to be opened at once. C) It prevents the file from being deleted. D) It reads the entire file into memory. Show Answer Correct Answer: A) It ensures that the file is closed after its block of code is executed. 7. What is an absolute path? A) A path that always begins with the root folder. B) A path that is relative to the program's current working directory. C) All the above. D) None of the above. Show Answer Correct Answer: A) A path that always begins with the root folder. 8. What is the output of the program in Program 13.4? A) The record is 2222222222. B) The record is 1111111111. C) Error in file opening. D) Total is 0. Show Answer Correct Answer: A) The record is 2222222222. 9. The regular text file have-extension A) .csv. B) .txt. C) .rtf. D) .ini. Show Answer Correct Answer: B) .txt. 10. Which of the following classes define in java.io and used for file handling are abstract?i) Readerii) FileWriteriii) InputStreamiv) FileInputStreamv) PrintStream A) I, iv & v. B) Only i. C) I & iii both. D) Ii, iii & v. Show Answer Correct Answer: C) I & iii both. 11. Close the file with fclose() function. A) Yes. B) Can not say. C) Can be yes or no. D) No. Show Answer Correct Answer: A) Yes. 12. Public class X { public static void main(String [] args) { try { badMethod(); System.out.print("A"); } catch (RuntimeException ex) /* Line 10 */ { System.out.print("B"); } catch (Exception ex1) { System.out.print("C"); } finally { System.out.print("D"); } System.out.print("E"); } public static void badMethod() { throw new RuntimeException(); } } A) DE. B) BDE. C) BD. D) BD. Show Answer Correct Answer: B) BDE. 13. What is the purpose of fprintf()? A) Reads formatted input from a file. B) Deletes a file. C) Checks for end of file. D) Writes formatted output to a file. Show Answer Correct Answer: D) Writes formatted output to a file. 14. Which mode opens a file for reading only? A) R. B) W. C) A. D) X. Show Answer Correct Answer: A) R. 15. Is block parameter in flock() optional A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: A) True. 16. Which module is used to write and read binary files with objects? A) Csv. B) Os. C) Pickle. D) Random. Show Answer Correct Answer: C) Pickle. 17. Which function renames a file? A) Os.shift(). B) Os.move(). C) Os.replace(). D) Os.rename(). Show Answer Correct Answer: D) Os.rename(). 18. Which function is used to read data from Text File? A) Writelines. B) Pickle. C) Read( ). D) Dump. Show Answer Correct Answer: C) Read( ). 19. Is the following Python code valid?try:# Do somethingexcept:# Do somethingelse:# Do something A) Yes. B) No, there is no such thing as else. C) No, else cannot be used with except. D) No, else must come before except. Show Answer Correct Answer: A) Yes. 20. .... is the extension of binary files A) .Dat. B) .dat. C) .txt. D) .bin. Show Answer Correct Answer: B) .dat. 21. What does the 'seek()' function do? A) Reads data from a file. B) Closes the file. C) Writes data to a file. D) Sets the position of the file pointer. Show Answer Correct Answer: D) Sets the position of the file pointer. 22. File opening modes for CSV files are: A) Same as those for text files. B) Same as those for binary files. C) Different from text files and binary files. D) Mix of text files and binary files. Show Answer Correct Answer: A) Same as those for text files. 23. The command that terminates the resources in use and frees the system of this program. A) Close(. B) Closed(. C) Close(). D) Closed(). Show Answer Correct Answer: C) Close(). 24. Which function is used to append data to a file in Python? A) Add(). B) Insert(). C) Append(). D) Write(). Show Answer Correct Answer: D) Write(). 25. Dynamic allocation of struct uses: A) Alloc(). B) Malloc(). C) New struct. D) Getmem(). Show Answer Correct Answer: B) Malloc(). 26. Exp(), floor()belongs which module? A) Cmath.py. B) Statistics.py. C) Math.py. D) Urlib.py. Show Answer Correct Answer: C) Math.py. 27. Which method is used to write data to a file in Python? A) Append(). B) Write(). C) Read(). D) Print(). Show Answer Correct Answer: B) Write(). 28. Using append adds data to an existing file A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: A) True. 29. If there is no error, then what will the error() method return? A) TRUE. B) FALSE. C) Empty String. D) None. Show Answer Correct Answer: C) Empty String. 30. Try block may or may not contains catch blocks A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: A) True. 31. Which of these keywords is not a part of exception handling? A) Try. B) Finally. C) Thrown. D) Catch. Show Answer Correct Answer: C) Thrown. 32. What is the default mode when opening a file in Python? A) Write. B) Binary. C) Append. D) Text. Show Answer Correct Answer: D) Text. 33. Taran and Tanisha are discussing different file formats in Python for their data science project. They wonder what is a similarity between text files and CSV files. A) Both can only be read using the csv module. B) Both store data in plain text format. C) Both require a specific delimiter to separate data. D) Both are binary files by default. Show Answer Correct Answer: B) Both store data in plain text format. 34. A pointer variable can be A) Changed within a function. B) Returned by a function. C) Passed to a function as argument. D) Can be assigned an integer value. Show Answer Correct Answer: A) Changed within a function. 35. Which function of text file will read the content of the complete file? A) Redlines(). B) Read(). C) Read(4). D) Readline(). Show Answer Correct Answer: B) Read(). 36. Which of the following functions do you use to write data in the binary format? A) Dump. B) Output. C) Send. D) Write. Show Answer Correct Answer: A) Dump. 37. What is the significance of file modes like 'r', 'w', and 'a'? A) The significance of file modes like 'r', 'w', and 'a' lies in controlling file access for reading, writing, and appending data. B) File modes specify the file format for data storage. C) File modes determine the size of the file on disk. D) File modes are used to encrypt the contents of a file. Show Answer Correct Answer: A) The significance of file modes like 'r', 'w', and 'a' lies in controlling file access for reading, writing, and appending data. 38. What happens each time you call the 'writeline' function? A) It deletes the previous line. B) It overwrites the file. C) It writes data to the bottom of the file on a new line. D) It writes data to the top of the file. Show Answer Correct Answer: C) It writes data to the bottom of the file on a new line. 39. What is the output of print(add ..... two(2, 's'))? A) Error. B) 5. C) 3. D) None. Show Answer Correct Answer: A) Error. 40. How do you read a CSV file using the csv module? A) Use the csv.reader() function after opening the file with open(). B) Open the file in binary mode and read it line by line. C) Use the pandas library to read the file directly. D) Use the json.load() function to parse the CSV file. Show Answer Correct Answer: A) Use the csv.reader() function after opening the file with open(). 41. What exception is raised when trying to open a file in write mode that already exists? A) FileExistsError. B) TypeError. C) IOError. D) ValueError. Show Answer Correct Answer: A) FileExistsError. 42. If you open a file in 'append' mode, what can you do? A) Add new content at the end. B) Overwrite everything in the file. C) Read the file only. D) Delete the content. Show Answer Correct Answer: A) Add new content at the end. 43. Apa yang terjadi jika file yang dibuka dengan mode "w" sudah ada? A) Data akan ditambahkan di akhir file. B) Data akan dibaca dari file. C) File tidak dapat dibuka. D) File akan dihapus dan dibuat baru. Show Answer Correct Answer: D) File akan dihapus dan dibuat baru. 44. Which mode is used to open an existing file for both reading and writing? A) "a+". B) "r+". C) "w". D) "w+". Show Answer Correct Answer: B) "r+". 45. 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. 46. 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) Addrow(). B) Writerows(). C) Insert row(). D) Writerow(). Show Answer Correct Answer: D) Writerow(). 47. 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) Move the current file position to a different location at a defined offset. D) Determine if you can move the file position or not. Show Answer Correct Answer: C) Move the current file position to a different location at a defined offset. 48. How many number of text file are available in Python ..... A) 4. B) 3. C) 1. D) 2. Show Answer Correct Answer: D) 2. 49. 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. 50. What is the correct way to close a file in C++? A) Close(). B) FileClose(). C) Fclose(). D) CloseFile(). Show Answer Correct Answer: A) Close(). 51. What is the purpose of the 'pprint.pformat()' function? A) To format data as a string for saving. B) To pretty print data to the console. C) To read data from a file. D) To serialize data. Show Answer Correct Answer: A) To format data as a string for saving. 52. What is the purpose of saving data before closing a program? A) To update the program's code. B) To delete temporary files. C) To refresh the program. D) To prevent data loss. Show Answer Correct Answer: D) To prevent data loss. 53. Which of the following is an example of a recursive function? A) Def sum numbers(n):sum = 0for i in range(1, n+1):sum += ireturn sum. B) Def power(x, n):result = 1for i in range(n):result *= xreturn result. C) Def factorial(n):if n == 0:return 1else:return n * factorial(n-1). D) Def print numbers(n):for i in range(1, n+1):print(i). Show Answer Correct Answer: C) Def factorial(n):if n == 0:return 1else:return n * factorial(n-1). 54. Which method is used to read the entire contents of a file as a string in Python? A) Readline(). B) Readfile(). C) Readlines(). D) Read(). Show Answer Correct Answer: D) Read(). 55. 3 Which module is used to work with binary files? A) CSV module. B) Pickle module. C) Binary module. D) Math module. Show Answer Correct Answer: B) Pickle module. 56. 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. 57. How can you open a text file in read mode in Python? A) Open('file.txt', 'w'). B) Open('file.txt', 'r'). C) Open('file.txt', 'a'). D) Open('file.txt', 'x'). Show Answer Correct Answer: B) Open('file.txt', 'r'). 58. To count the number of words in a text file, the best approach is: A) Count spaces. B) Use .count(" "). C) Use .split() on each line. D) Count characters. Show Answer Correct Answer: C) Use .split() on each line. 59. 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. 60. What is the output of the program that writes to a file? A) File not found. B) Data written to file successfully. C) Data read from file. D) Error opening file. Show Answer Correct Answer: B) Data written to file successfully. ← 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 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