This quiz works best with JavaScript enabled. Home > Cbse > Class 11 > Science > Computer Science > Class 11 Computer Science Chapter 6 File Handling – Quiz 1 🏠 Homepage 📘 Download PDF Books 📕 Premium PDF Books Class 11 Computer Science Chapter 6 File Handling Quiz 1 (60 MCQs) Quiz Instructions Select an option to see the correct answer instantly. 1. The correct syntax of the len function for string x: A) Len(x). B) Len[x]. C) LEN[]. D) X.len(). Show Answer Correct Answer: A) Len(x). 2. The correct syntax to close the file (name of file handle F) A) F.close(). B) F.close. C) Close(F). D) F(close). Show Answer Correct Answer: A) F.close(). 3. In order to work with a pickle mode you must first import A) Pickle. B) Stdin(). C) Stderr(). D) Stdout(). Show Answer Correct Answer: A) Pickle. 4. Delimeter for CSV file is A) Comma. B) Semi-colon. C) Space. D) Tab. Show Answer Correct Answer: A) Comma. 5. Choose the correct syntax of the replace function: A) X.replace("j", "3"). B) X.replace(3, x). C) X.replace(y). D) X.Replace(x). Show Answer Correct Answer: A) X.replace("j", "3"). 6. What does the 'r' mode do when opening a file? A) Opens a file for writing. B) Creates a new file. C) Opens a file for appending. D) Opens a file for reading. Show Answer Correct Answer: D) Opens a file for reading. 7. What is the purpose of the rewind() function? A) Reset file pointer to beginning. B) Move pointer to end. C) Check for errors. D) Close the file. Show Answer Correct Answer: A) Reset file pointer to beginning. 8. Inorder to avoid conflicts what concept is used in files A) Fblock(). B) Fclock(). C) Flock(). D) None. Show Answer Correct Answer: C) Flock(). 9. To create a csv file sales.csv, the correct syntax is ..... A) F=open('sales.csv', 'w+'). B) F=open('sales.csv', 'w'). C) F=open('sales.csv', 'a'). D) F=open('sales.csv', 'r'). Show Answer Correct Answer: B) F=open('sales.csv', 'w'). 10. How do you ensure that a file is properly closed after operations? A) Use a context manager or ensure to close the file in a finally block. B) Close the file only if an error occurs. C) Use a global variable to track the file state. D) Leave the file open until the program ends. Show Answer Correct Answer: A) Use a context manager or ensure to close the file in a finally block. 11. Which logical operator used to check for any one condition to be true? A) Or. B) And. C) Not. D) None. Show Answer Correct Answer: A) Or. 12. Fwrite() is used to write: A) Structure data. B) Only integer. C) Only char. D) File name. Show Answer Correct Answer: A) Structure data. 13. How do you write data to a binary file in Python? A) Use open('filename', 'rb') to read a binary file and file.read() to retrieve bytes. B) Write data to a text file using open('filename', 'w') and file.write(data) for strings. C) Use open('filename', 'wb') to open a binary file and file.dump(data) to write bytes. D) Use open('filename', 'wb+') to open a binary file and file.load(data) to add bytes. Show Answer Correct Answer: C) Use open('filename', 'wb') to open a binary file and file.dump(data) to write bytes. 14. Which of the following options is the correct Python statement to read and displaythe first 10 characters of a text file "poem.txt" ? A) F=open('poem.txt') print(F.read(10)). B) F=open('poem.txt', ) print(F.readline(10)). C) F=open('poem.txt') print(F.reader(10)). D) F=open('poem.txt') print(F.load(10)). Show Answer Correct Answer: A) F=open('poem.txt') print(F.read(10)). 15. Files being used by programs are copied into main memory A) TRUE. B) FALSE. C) All the above. D) None of the above. Show Answer Correct Answer: A) TRUE. 16. Which function is used to write all the charecters A) Write(). B) Writecharecters(). C) Writeall. D) Writechar(). Show Answer Correct Answer: A) Write(). 17. What is the use of "a" in file handling? A) Read. B) Write. C) Append. D) None of the mentioned. Show Answer Correct Answer: C) Append. 18. Which Python library is commonly used for GUI programming involving widgets like Label and Button? A) Tkinter. B) NumPy. C) Pandas. D) Matplotlib. Show Answer Correct Answer: A) Tkinter. 19. How do you read the entire content of a file in Python? A) Use 'open("filename.txt") as file:content = file.read()'. B) Read the file using 'file = open("filename.txt", "r") content = file.read()'. C) Use 'with open("filename.txt", "r") as file:content = file.read()'. D) Employ 'with open("filename.txt") as file:content = file.readlines()'. Show Answer Correct Answer: C) Use 'with open("filename.txt", "r") as file:content = file.read()'. 20. Why is it important to close a file in Python? A) To avoid syntax errors. B) To delete the file. C) To free up system resources. D) To convert the file to binary format. Show Answer Correct Answer: C) To free up system resources. 21. CSV stands for ..... A) Common separate variable. B) Comma Separates Values. C) Comma Separated Values. D) Common Separated Values. Show Answer Correct Answer: C) Comma Separated Values. 22. Which of the following is NOT a basic file handling operation? A) Read. B) Open. C) Delete. D) Write. Show Answer Correct Answer: C) Delete. 23. The ..... function changes the position of the file pointer by placing the file pointer at the specified position in an open file A) Tell(). B) Loc. C) Pos(). D) Seek(). Show Answer Correct Answer: D) Seek(). 24. What is the difference between text and binary files? A) Text files are human-readable; binary files are not. B) Binary files can be opened in any text editor. C) Text files contain only images and videos. D) Text files are always larger than binary files. Show Answer Correct Answer: A) Text files are human-readable; binary files are not. 25. Which mode is correct for writing binary file? A) "w+". B) "wb". C) "bw". D) "w". Show Answer Correct Answer: B) "wb". 26. Which mode is used to open a binary file for writing? A) Rb. B) R. C) W. D) Wb. Show Answer Correct Answer: D) Wb. 27. Fread() reads contents of file A) Word by word till eof. B) Paragraph by paragraph till end of file. C) Line by line till eof. D) None. Show Answer Correct Answer: C) Line by line till eof. 28. How do you read a file line by line in Python? A) Use 'open("filename.txt") and file.read()' to get the content as a single string. B) Use 'file.readlines()' to read all lines in a file. C) Use 'open("filename.txt") as file:file.read()' to read the entire file at once. D) Use 'with open("filename.txt") as file:for line in file:print(line)'. Show Answer Correct Answer: D) Use 'with open("filename.txt") as file:for line in file:print(line)'. 29. How do you handle exceptions while working with Fileinputstream and Fileoutputstream in Java? A) Use try-catch blocks to catch and handle IOException. B) Use if-else statements to handle IOException. C) Throw a new custom exception instead of catching IOException. D) Ignore the exception and continue with the program. Show Answer Correct Answer: A) Use try-catch blocks to catch and handle IOException. 30. Describe how to serialize an object in Python. A) Use 'xml.etree.ElementTree' to serialize the object to XML. B) Use 'pickle.dump(object, file)' for binary serialization. C) Use 'json.dumps(object)' for JSON serialization. D) Convert the object to a string using 'str(object)' before saving. Show Answer Correct Answer: C) Use 'json.dumps(object)' for JSON serialization. 31. Ali opens a file with mode "r" . He tries to write new data into it, but an error occurs. Why? A) The file is locked for editing. B) The file is already closed. C) The file is opened as read-only, not writable. D) The file does not exist. Show Answer Correct Answer: C) The file is opened as read-only, not writable. 32. Dalam C++, fungsi mana yang digunakan untuk membuka file? A) Create(). B) Open(). C) Start(). D) Init(). Show Answer Correct Answer: B) Open(). 33. Using append overwrites all data in a text file A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: B) False. 34. Which function is used to read a single line from a file A) Readlines(). B) Readfullline. C) Readline(). D) Readstatement(). Show Answer Correct Answer: C) Readline(). 35. What is the code to open a file named as new ..... file in write mode and truncate it if it already exists? A) Open(ios::out | ios::trunc, "new file.dat" );. B) Open( | , "new file.dat" );. C) Open("new file.dat", | );. D) Open("new file.dat", ios::out | ios::trunc );. Show Answer Correct Answer: D) Open("new file.dat", ios::out | ios::trunc );. 36. What are the different modes of opening a file in C++? A) Ios::in, ios::out, ios::app, ios::ate, ios::trunc, ios::binary. B) Ios::read. C) Ios::create. D) Ios::write. Show Answer Correct Answer: A) Ios::in, ios::out, ios::app, ios::ate, ios::trunc, ios::binary. 37. What does the tell() function return in Python file handling? A) Current position of the file pointer. B) Total file size. C) Number of lines in the file. D) File creation date. Show Answer Correct Answer: A) Current position of the file pointer. 38. In Python, which function do you use to open a file? A) Start(). B) Open(). C) Load(). D) Read(). Show Answer Correct Answer: B) Open(). 39. What is the purpose of closing a file after it is no longer being used? A) To prevent data corruption. B) To write data automatically. C) To delete the file. D) To change file permissions. Show Answer Correct Answer: A) To prevent data corruption. 40. Which exception is thrown when divide by zero occurs? A) NumberFormatException. B) ArithmeticException. C) NullPointerException. D) None of these. Show Answer Correct Answer: B) ArithmeticException. 41. How do you close a file after performing file operations in C++? A) 'file.end()'. B) 'file.read()'. C) 'file.close()'. D) 'file.open()'. Show Answer Correct Answer: C) 'file.close()'. 42. What will be the output of the following code snippet?f = Nonefor i in range (5):with open("myfile.txt", "w") as f:if i > 2:breakprint (f.closed) A) True. B) Runtime Error. C) False. D) Hello world. Show Answer Correct Answer: A) True. 43. What is the result of trying to access an index that is out of range in a list? A) ValueError. B) IndexError. C) NameError. D) TypeError. Show Answer Correct Answer: B) IndexError. 44. Which of the following class is used for input and output operation when working with characters? A) InputStream. B) OutputStream. C) Writer. D) All of given. Show Answer Correct Answer: C) Writer. 45. How is Java serialization achieved? A) By using the java.io.Serialization class. B) By calling the serialize() method. C) By implementing the java.io.Serializable interface. D) By setting the serialization flag to true. Show Answer Correct Answer: C) By implementing the java.io.Serializable interface. 46. What is the purpose of the 'close' method in file handling? A) To create a new file and write data to it. B) To close an open file and release resources. C) To delete a file from the system permanently. D) To read data from a file and store it. Show Answer Correct Answer: B) To close an open file and release resources. 47. Which is/are the basic I/O (input-output) stream(s) in file? A) Standard Input. B) Standard Output. C) Standard Errors. D) All of these. Show Answer Correct Answer: D) All of these. 48. Why is Binary File Handling important in Python programming? A) Binary File Handling is crucial for handling non-text files and preserving data integrity. B) Binary File Handling can corrupt data easily. C) Binary File Handling is only useful for text files. D) Binary File Handling is not supported in Python. Show Answer Correct Answer: A) Binary File Handling is crucial for handling non-text files and preserving data integrity. 49. How can you handle exceptions when working with binary files? A) Always read binary files in text mode. B) Use try-except blocks to catch exceptions like IOError or EOFError when working with binary files. C) Use print statements to debug binary file operations. D) Ignore exceptions when working with binary files. Show Answer Correct Answer: B) Use try-except blocks to catch exceptions like IOError or EOFError when working with binary files. 50. What is the purpose of using a list for records in Python? A) To store only strings. B) To store only numbers. C) To store only functions. D) To store different data types. Show Answer Correct Answer: D) To store different data types. 51. Which function is used to write a list of Strings in a file? A) Writeline(). B) Writelines(). C) Writestatement(). D) Writefullline(). Show Answer Correct Answer: B) Writelines(). 52. Explain the difference between read() and readline() in Python file handling. A) Read() is used for binary files; readline() is used for text files. B) Read() reads one line at a time; readline() reads the whole file at once. C) Read() reads a specified number of bytes; readline() reads the entire file. D) Read() reads the whole file at once; readline() reads one line at a time. Show Answer Correct Answer: D) Read() reads the whole file at once; readline() reads one line at a time. 53. Why is it important to close a file after operations are completed? A) To save changes to the file. B) To free up system resources. C) All of the above. D) To prevent data corruption. Show Answer Correct Answer: B) To free up system resources. 54. In binary file, there is no delimiter for a line. A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: A) True. 55. In pseudocode, how do you append data to a file? A) 'WRITE data TO file'. B) 'OPEN file FOR APPEND'. C) 'APPEND data TO file'. D) 'READ data FROM file'. Show Answer Correct Answer: B) 'OPEN file FOR APPEND'. 56. Reading from a file often involves using ..... A) A loop. B) An condition. C) Comments. D) None of the above. Show Answer Correct Answer: A) A loop. 57. Which of the following is used to open a file in read mode? A) S. B) R. C) Read. D) Rd. Show Answer Correct Answer: B) R. 58. To read 2 characters from a file object fobj, the command should be: A) Fobj.readline(). B) Fobj.read2(). C) Fobj.read(). D) Fobj.read(2). Show Answer Correct Answer: D) Fobj.read(2). 59. Discuss the different modes used for opening a file in Python. A) Different modes used for opening a file in Python are 'r', 'w', 'a', 'r+', 'w+', and 'a+'. B) Z. C) Y. D) X. Show Answer Correct Answer: A) Different modes used for opening a file in Python are 'r', 'w', 'a', 'r+', 'w+', and 'a+'. 60. Which mode should be specified in the 'open()' function when you need to write to a file? A) "x". B) "r". C) "w". D) "a". Show Answer Correct Answer: C) "w". Next →Related QuizzesScience QuizzesClass 11 QuizzesClass 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 9 🏠 Back to Homepage 📘 Download PDF Books 📕 Premium PDF Books