This quiz works best with JavaScript enabled. Home > Cbse > Class 11 > Science > Computer Science > Class 11 Computer Science Chapter 6 File Handling – Quiz 13 🏠 Homepage 📘 Download PDF Books 📕 Premium PDF Books Class 11 Computer Science Chapter 6 File Handling Quiz 13 (60 MCQs) Quiz Instructions Select an option to see the correct answer instantly. 1. How can you read only part of a file? A) By specifying the number of characters in the 'read()' function. B) Deleting parts of the file first. C) Opening the file in 'write' mode. D) Using the 'write()' function. Show Answer Correct Answer: A) By specifying the number of characters in the 'read()' function. 2. What does the exists() method check for a Path object? A) If the path is an absolute path. B) If the path points to a valid file or directory. C) All the above. D) None of the above. Show Answer Correct Answer: B) If the path points to a valid file or directory. 3. In binary file data is used in A) Byte. B) Text. C) Graphics. D) None. Show Answer Correct Answer: A) Byte. 4. What will be the output of the following code?f=open('abc.txt', 'w')print(f.close) A) 0. B) True. C) 1. D) False. Show Answer Correct Answer: D) False. 5. What is the purpose of the first argument in the 'fopen()' function? A) To indicate the name of the file to be opened. B) To set the permissions for the file. C) To define the size of the file to be opened. D) To specify the mode in which the file should be opened. Show Answer Correct Answer: A) To indicate the name of the file to be opened. 6. Which Python module is used to interact with the operating system for file operations? A) Os. B) Pickle. C) Csv. D) Sys. Show Answer Correct Answer: A) Os. 7. Name the two function used to read and write in binary files A) Read(), Write(). B) Dump(), Load(). C) Pickle(), Unpickle(). D) Seek(), Tell(). Show Answer Correct Answer: B) Dump(), Load(). 8. What is the purpose of the 'close' operation in file handling? A) To save changes to the file. B) To delete the file. C) To free up resources. D) To rename the file. Show Answer Correct Answer: C) To free up resources. 9. Which of the following is NOT a valid method of handling file operations? A) Closing a file after reading or writing to it. B) Storing a file's contents directly in a Boolean variable. C) Writing data to a file using an appropriate file mode. D) Opening a file before reading data from it. Show Answer Correct Answer: B) Storing a file's contents directly in a Boolean variable. 10. Which function is used to pickle data to a binary file? A) Pickle.read(). B) Pickle.dump(). C) Pickle.load(). D) Pickle.write(). Show Answer Correct Answer: B) Pickle.dump(). 11. Files can be opened in multiple modes at the same time A) TRUE. B) FALSE. C) All the above. D) None of the above. Show Answer Correct Answer: B) FALSE. 12. I want an array that stores 10 values, which of the following is correct? A) MyArray{10}. B) MyArray[1]. C) MyArray10. D) MyArray[10]. Show Answer Correct Answer: D) MyArray[10]. 13. What is the use of "w" in file handling? A) Read. B) Write. C) Append. D) None of the above. Show Answer Correct Answer: B) Write. 14. Which keyword is used to use(add) a module in Python Programming? A) Insert. B) Input. C) Import. D) None. Show Answer Correct Answer: C) Import. 15. What is the return type of fopen()? A) FILE. B) Int. C) FILE *. D) Char *. Show Answer Correct Answer: C) FILE *. 16. Which function serializes objects to binary file? A) Store(). B) Write(). C) Save(). D) Dump(). Show Answer Correct Answer: D) Dump(). 17. Which of the following statements are true regarding the opening modes of a file? A) When you open a file for reading, if the file does not exist, an error occurs. B) When you open a file for writing, if the file does not exist, an error occurs. C) When you open a file for reading, if the file does not exist, the program will open an empty file. D) None of the above. Show Answer Correct Answer: A) When you open a file for reading, if the file does not exist, an error occurs. 18. Which statement is used to change the file position to an offset value from the start? A) Fp.seek(offset, 0). B) Fp.seek(offset, 1). C) Fp.seek(offset, 2). D) None of these. Show Answer Correct Answer: A) Fp.seek(offset, 0). 19. Which command properly closes a file in Python? A) File.close(). B) File.quit(). C) File.end(). D) File.exit(). Show Answer Correct Answer: A) File.close(). 20. Which class is used to read the contents of a text file in Java? A) FileWriter. B) FileReader. C) BufferedWriter. D) Scanner. Show Answer Correct Answer: D) Scanner. 21. What is the best way to read the first line of a file? A) .read(). B) .readline(). C) .readlines(). D) .read(all). Show Answer Correct Answer: B) .readline(). 22. The correct syntax of with statement is ..... A) With open(, ) as . B) With Open(, ) . C) With open(, ) as :. D) All of the above. Show Answer Correct Answer: C) With open(, ) as :. 23. The tab separated value file extension are ..... A) .csv. B) .tsv. C) .txt. D) All these. Show Answer Correct Answer: B) .tsv. 24. What does ferror() check for? A) Closes an open file. B) Reads data from a file. C) Opens a file. D) Checks for file errors. Show Answer Correct Answer: D) Checks for file errors. 25. What should you do after finishing reading from a file? A) Close the file. B) Rename the file. C) Leave it open. D) Delete the file. Show Answer Correct Answer: A) Close the file. 26. This file does not have EOL character to mark the end of line A) Binary Files. B) Text Files. C) All the above. D) None of the above. Show Answer Correct Answer: A) Binary Files. 27. In file handling, what does this term means"r, a" ? A) Read, append. B) Append, read. C) All of the mentioned. D) None of these. Show Answer Correct Answer: A) Read, append. 28. What is the purpose of the mkdir() method? A) To rename a file. B) To delete a directory. C) To create a file. D) To create a directory. Show Answer Correct Answer: D) To create a directory. 29. What is the home directory? A) A folder for user files. B) A system folder. C) A type of file. D) A temporary storage location. Show Answer Correct Answer: A) A folder for user files. 30. How do you pass a default argument to a function? A) Call the function without any arguments. B) Define the function with default values, e.g., def my function(param1=default value):. C) Use a global variable instead of a parameter. D) Define the function without any parameters. Show Answer Correct Answer: B) Define the function with default values, e.g., def my function(param1=default value):. 31. Which constant is used to position the next I/O operation relative to the current position in fseek() function? A) SEEK END. B) SEEK SET. C) SEEK BEG. D) SEEK CUR. Show Answer Correct Answer: D) SEEK CUR. 32. What is the extension of a text file? A) .text. B) .txt. C) .tet. D) .ext. Show Answer Correct Answer: B) .txt. 33. Which mode is used to open a file for both reading and writing, creating the file if it doesn't exist, and truncating the file if it exists in Python? A) X+. B) R+. C) W+. D) A+. Show Answer Correct Answer: C) W+. 34. Which file mode will allow reading and writing without truncating existing data? A) 'r+'. B) 'w+'. C) 'a+'. D) Both a and c. Show Answer Correct Answer: A) 'r+'. 35. What is the output of the following code?file = open('data.txt', 'r')print(file.read())file.close() A) An error will occur because the file is not opened in read mode. B) The code will print the file object instead of its contents. C) The contents of the 'data.txt' file will be printed. D) The file 'data.txt' does not exist. Show Answer Correct Answer: C) The contents of the 'data.txt' file will be printed. 36. Which of the following is not a mode for opening files? A) Replace. B) Append. C) Read. D) Write. Show Answer Correct Answer: A) Replace. 37. What is the purpose of the 'open' function in file handling? A) To delete a file. B) To open a file. C) To rename a file. D) To close a file. Show Answer Correct Answer: B) To open a file. 38. How can you write to a file in Python? A) Use the 'read' method to add content to the file. B) Write the content directly to the file without opening it. C) Open the file in read mode and directly modify its content. D) Open the file in write mode, use the 'write' method to add content, and close the file. Show Answer Correct Answer: D) Open the file in write mode, use the 'write' method to add content, and close the file. 39. What is the correct way to ensure a file is closed after operations are completed? A) Use the 'write()' method. B) Use the 'close()' method. C) Use the 'open()' method. D) Use the 'read()' method. Show Answer Correct Answer: B) Use the 'close()' method. 40. When a number is divided by 0, ..... is raised A) Zero division error. B) Index error. C) Import error. D) Name error. Show Answer Correct Answer: A) Zero division error. 41. Which module in Python is used for reading and writing binary files by converting Python objects into a byte stream and vice versa? A) Csv. B) Math. C) Pickle. D) Pandas. Show Answer Correct Answer: C) Pickle. 42. What is the expected output of the function add ..... two when called with parameters 2 and 1? A) 3. B) 1. C) Error. D) None. Show Answer Correct Answer: A) 3. 43. What is the difference between positional and keyword arguments? A) Positional arguments require the correct order, whereas keyword arguments allow for named parameters. B) Positional arguments can be used without any order. C) Keyword arguments are always mandatory in functions. D) Positional arguments are only used in class methods. Show Answer Correct Answer: A) Positional arguments require the correct order, whereas keyword arguments allow for named parameters. 44. When we open file in writing mode what will happen? A) All the previous data will be deleted. B) All the previous data will not be deleted. C) Both can be happen depending on the situation. D) None. Show Answer Correct Answer: A) All the previous data will be deleted. 45. ..... keyword is used to insert a module A) Import. B) Insert. C) Input. D) All These. Show Answer Correct Answer: A) Import. 46. How can you handle exceptions when opening a file in Python? A) Use a for loop to iterate through the file contents. B) Use a try-except block to catch exceptions when opening a file. C) Open the file without any error handling. D) Use a print statement to display the file contents. Show Answer Correct Answer: B) Use a try-except block to catch exceptions when opening a file. 47. Mode argument is mandatory. A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: B) False. 48. What will be the output-f=open('abc.txt', 'a')text="xyz"f.write(text)f.close() A) Writing into the file by erasing old content. B) Reading from the file without erasing old content. C) Reading from 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. 49. What will be the output-f=open('abc.txt', 'w')print(f.name) A) Abc. B) Abc.txt. C) File. D) 'w'. Show Answer Correct Answer: B) Abc.txt. 50. We need not to close the file if we are opening file with 'with open( ..... ) as ..... block A) Yes. B) No. C) All the above. D) None of the above. Show Answer Correct Answer: A) Yes. 51. How do you create a cookie in PHP? A) Setcookie(). B) Createcookie. C) Makecookie(). D) None. Show Answer Correct Answer: A) Setcookie(). 52. Which of the following class is used to read characters from a file? A) FileInputStream. B) FileReader. C) InputStreamReader. D) FileWriter. Show Answer Correct Answer: B) FileReader. 53. When would you use the Load function in Python? A) Deserializing of data. B) Creating a new Python package. C) Connecting to a database. D) Sorting a list of integers. Show Answer Correct Answer: A) Deserializing of data. 54. Both "w" mode and "a" mode can be used to edit a file. A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: A) True. 55. What does the OPENFILE command do in file handling? A) Closes the file. B) Reads data from the file. C) Opens the file for reading, writing, or both. D) Deletes the file. Show Answer Correct Answer: C) Opens the file for reading, writing, or both. 56. If I want to add to the end of a text file, I should: A) MyCipher = open("MyCipher.txt", "w"). B) MyCipher = open("MyCipher.txt", "a"). C) MyCipher = open("MyCipher.txt", "w+"). D) MyCipher = open("MyCipher.txt", "s"). Show Answer Correct Answer: B) MyCipher = open("MyCipher.txt", "a"). 57. Jika kita ingin menghapus isi lama saat membuka file, kita memakai apa? A) Ios::trunc. B) Ios::app. C) Ios::out. D) Ios::in. Show Answer Correct Answer: A) Ios::trunc. 58. Which method is used to delete a file in Java? A) Erase(). B) Delete(). C) Remove(). D) Clear(). Show Answer Correct Answer: B) Delete(). 59. The PHP ..... function is used to open a file. A) Fopen(). B) Insert(). C) Create(). D) Open(). Show Answer Correct Answer: A) Fopen(). 60. What will be the output of the following C code? (Assuming size of char = 1, int = 4, double = 8) #include union utemp { int a; double b; char c; }u; int main() { u.c = 'A'; u.a = 1; printf("%zu", sizeof(u)); } A) 1. B) 13. C) 4. D) 8. Show Answer Correct Answer: D) 8. ← 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