This quiz works best with JavaScript enabled. Home > Cbse > Class 11 > Science > Computer Science > Class 11 Computer Science Chapter 6 File Handling – Quiz 5 🏠 Homepage 📘 Download PDF Books 📕 Premium PDF Books Class 11 Computer Science Chapter 6 File Handling Quiz 5 (60 MCQs) Quiz Instructions Select an option to see the correct answer instantly. 1. Which of the following function returns a list datatype A) D=f.read(10). B) D=f.readlines(). C) D=f.readline(). D) D=f.read(). Show Answer Correct Answer: B) D=f.readlines(). 2. Which mode should you use to open a file for writing in text mode, creating it if it doesn't exist? A) "t". B) "w". C) "b". D) "r". Show Answer Correct Answer: B) "w". 3. 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. 4. Mode apa yang digunakan untuk menulis ke file baru dalam fopen? A) "w". B) "rb". C) "a". D) "r". Show Answer Correct Answer: A) "w". 5. How can you create a new file if it does not exist when opening it? A) Use 'open("filename.txt", "x")' to create a new file. B) Use 'open("filename.txt", "r")' to read the file. C) Use 'open("filename.txt", "w")' or 'open("filename.txt", "a")' in Python. D) Use 'open("filename.txt", "b")' for binary mode. Show Answer Correct Answer: C) Use 'open("filename.txt", "w")' or 'open("filename.txt", "a")' in Python. 6. What happens if fopen("abc.txt", "r") fails? A) Returns NULL. B) Creates file. C) Returns 0. D) Program crashes. Show Answer Correct Answer: A) Returns NULL. 7. What does the 'r' mode in the 'open()' function signify? A) Read from the file. B) Execute the file. C) Write to the file. D) Append to the file. Show Answer Correct Answer: A) Read from the file. 8. What happens if you try to close a file that is already closed? A) An error is raised. B) Nothing happens. C) The file gets corrupted. D) The file gets reopened. Show Answer Correct Answer: B) Nothing happens. 9. In CSV file all data's are stored in ..... format A) Gif. B) Table. C) Animation. D) Image. Show Answer Correct Answer: B) Table. 10. What is the purpose of the sys.path list? A) To keep track of all open files. B) To search for modules when importing. C) To store the current directory path. D) To list all Python keywords. Show Answer Correct Answer: B) To search for modules when importing. 11. The csv file is a ..... file. A) Plain text. B) Binary. C) Combination of both. D) None of the above. Show Answer Correct Answer: A) Plain text. 12. What happens if the CSV file being read by Reyansh contains inconsistent row lengths? A) All rows will be padded with empty values to match the longest row. B) The CSV file will be ignored entirely if row lengths are inconsistent. C) Inconsistent row lengths are automatically corrected during the read process. D) Inconsistent row lengths can cause errors or misalignment in data when reading a CSV file. Show Answer Correct Answer: D) Inconsistent row lengths can cause errors or misalignment in data when reading a CSV file. 13. ..... Open the file for writing. The file is created if it does not exist. A) R. B) W. C) Open(). D) A. Show Answer Correct Answer: D) A. 14. What will be the ouput-f=open('abc.txt', 'w')x=f.read()f.close()print(x) A) Error(not readable). B) Error(not writable). C) It will read all the data of the file. D) None. Show Answer Correct Answer: A) Error(not readable). 15. What is the role of the function fputs in file handling? A) To read the contents of a file. B) To check if the file has reached the end. C) To determine if the file has been opened successfully. D) To write a string of text to a file. Show Answer Correct Answer: D) To write a string of text to a file. 16. Which types of file requires translation? A) Text file. B) Binary file. C) CSV file. D) All files. Show Answer Correct Answer: A) Text file. 17. File handling isn't needed as programs can save data to be accessed again later without them A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: B) False. 18. A stream is a sequence of data and stream is composed of ..... A) Bits. B) Bytes. C) Both bits and Bytes. D) None of given. Show Answer Correct Answer: B) Bytes. 19. How can standard output be redirected to a file in Python? A) Print('data', file=fileobject). B) Sys.stdout.writelines(). C) Reassigning sys.stdout. D) Sys.stdout.write(). Show Answer Correct Answer: A) Print('data', file=fileobject). 20. What will be the output of the following code?import mathprint(math.sqrt(16)) A) 2. B) 8. C) Error. D) 4. Show Answer Correct Answer: D) 4. 21. Which mode should be used with the 'open()' function to append data to an existing file? A) 'a'. B) 'r'. C) 'w'. D) 'r+'. Show Answer Correct Answer: A) 'a'. 22. ..... and ..... are the two objects associated with the csv module to read and write onto a CSV file. A) Reader() and writer(). B) Read() and write(). C) Dump() and load(). D) Write() and writelines(). Show Answer Correct Answer: A) Reader() and writer(). 23. Whether following code create file xyz.txt or not?import java.io.*; class demoFile { public static void main(String args[]) { try { File f = new File("C:/java/xyz.txt"); } catch(Exception e) { } catch(IOException e) { } } } A) True. B) Compailation Error. C) False. D) Runtime Error. Show Answer Correct Answer: B) Compailation Error. 24. Which function is used to write multiple lines in text file? A) Writelines(). B) Write(). C) Print(). D) Writeline(). Show Answer Correct Answer: A) Writelines(). 25. What is a binary file and how does it differ from a text file? A) A binary file is always smaller than a text file. B) A binary file contains non-human-readable data, while a text file contains human-readable text. C) Text files can only contain numbers, while binary files can contain letters. D) Binary files are only used for images and videos. Show Answer Correct Answer: B) A binary file contains non-human-readable data, while a text file contains human-readable text. 26. What is the correct order of operations for writing data to a file? A) Open, write, close. B) Write, open, close. C) Close, open, write. D) Open, close, write. Show Answer Correct Answer: A) Open, write, close. 27. EOL can be expanded as A) Error of Line. B) End of Lock. C) End of Letter. D) End of Line. Show Answer Correct Answer: D) End of Line. 28. Which character can work as delimiter for CSV files: A) Comma only. B) Space only. C) Any character. D) Tab only. Show Answer Correct Answer: C) Any character. 29. What happens to the content of a file when opened in 'WRITE' mode? A) The content is overwritten. B) The content remains unchanged. C) The content is appended. D) The content is read-only. Show Answer Correct Answer: A) The content is overwritten. 30. Which file type is more secure? A) Csv file. B) Text file. C) Binary file. D) All of the above. Show Answer Correct Answer: C) Binary file. 31. Which function returns the current position of file pointer? A) Seek(). B) Tell(). C) Getpos(). D) Position(). Show Answer Correct Answer: B) Tell(). 32. Which PHP function is used to open a file for reading or writing? A) File(). B) Open file(). C) File open(). D) Fopen(). Show Answer Correct Answer: D) Fopen(). 33. What is involved in the process of writing to a file? A) Creating a new file. B) Deleting data from a file. C) Adding data to a file. D) Reading data from a file. Show Answer Correct Answer: C) Adding data to a file. 34. Files are kept in secondary storage A) TRUE. B) FALSE. C) All the above. D) None of the above. Show Answer Correct Answer: A) TRUE. 35. A function can return A) Returns 0. B) Cant return any value. C) It can return multiple values. D) Only single value. Show Answer Correct Answer: C) It can return multiple values. 36. What will be the output of following codevoid main { ofstream out ..... obj; out ..... obj.open ("abc.txt"); out ..... obj << "MOOCS" << endl;cout << "Data written to file" << endl;out ..... obj.close(); } A) Compile error. B) Program will print "written to file". C) Program will write "MOOCS" into abc.txt. D) None of the above. Show Answer Correct Answer: C) Program will write "MOOCS" into abc.txt. 37. Which of these packages contain classes and interfaces used for input & output operations of a program? A) Java.util. B) Java.lang. C) Java.io. D) All of the mentioned. Show Answer Correct Answer: C) Java.io. 38. What is the actual use of ofstream? A) It helps to switch off the streams. B) It help to write on the file. C) It helps to read from file. D) It allows to both read and write on the file. Show Answer Correct Answer: B) It help to write on the file. 39. Which method is used to open a file in Python? A) Read(). B) Append(). C) Write(). D) Open(). Show Answer Correct Answer: D) Open(). 40. A logical group of related objects are known as A) Global space. B) Local space. C) Memory. D) Namespace. Show Answer Correct Answer: D) Namespace. 41. ..... In this type of file, there is no terminator for a line and the data is stored after converting it into machine understandable binary language. A) Binary Files. B) Character Files. C) Bin File. D) Text Files. Show Answer Correct Answer: A) Binary Files. 42. What is the last thing you should do to a file? A) Save. B) Close. C) Write. D) Read. Show Answer Correct Answer: B) Close. 43. Which attribute provides information about a file object in Python? A) File Positions. B) File Object Attributes. C) Writelines() method. D) Seek() function. Show Answer Correct Answer: B) File Object Attributes. 44. What does the program that reads from a file do? A) Prints the contents of the file. B) Checks for end of file. C) Writes data to the file. D) Opens a file. Show Answer Correct Answer: A) Prints the contents of the file. 45. What is the default mode for opening a file in Python? A) X. B) W. C) A. D) R. Show Answer Correct Answer: D) R. 46. Apa yang dilakukan fungsi fclose? A) Menutup file. B) Membaca data dari file. C) Menulis data ke file. D) Membuka file. Show Answer Correct Answer: A) Menutup file. 47. Can you read a CSV file using the same method as reading a text file in Python? A) Sometimes. B) Maybe. C) No. D) Yes. Show Answer Correct Answer: D) Yes. 48. How do you read a single line from a file using Python? A) Line = open('filename.txt').readlines(). B) Line = open('filename.txt').readline(). C) Line = open('filename.txt').readline(0). D) Line = open('filename.txt').read(). Show Answer Correct Answer: B) Line = open('filename.txt').readline(). 49. Apa yang dilakukan mode "a" saat membuka file? A) Menulis data baru ke file. B) Menambahkan data ke akhir file. C) Membaca data dari file. D) Menghapus isi file. Show Answer Correct Answer: B) Menambahkan data ke akhir file. 50. When we open file in reading mode the initial position of the cursor is- A) 0. B) After the last written word. C) Middle of the file. D) None. Show Answer Correct Answer: A) 0. 51. What is the purpose of the 'with' statement when opening files? A) To write files in append mode. B) To read files in binary mode. C) To open multiple files at once. D) To ensure the file is closed automatically. Show Answer Correct Answer: D) To ensure the file is closed automatically. 52. Which of the following is NOT a valid file mode in Python? A) R. B) A. C) W. D) D. Show Answer Correct Answer: D) D. 53. What is the correct syntax to open a file for reading? A) Open('file.txt', 'w'). B) Read('file.txt'). C) File('file.txt'). D) Open('file.txt', 'r'). Show Answer Correct Answer: D) Open('file.txt', 'r'). 54. Which method is used to write a sequence of strings to a file in Python? A) Write(). B) Read(). C) Readlines(). D) Writelines(). Show Answer Correct Answer: D) Writelines(). 55. Apa yang akan terjadi jika fopen gagal membuka file? A) Program akan berhenti. B) File akan dibuat. C) Data akan ditulis ke file. D) Mengembalikan NULL. Show Answer Correct Answer: D) Mengembalikan NULL. 56. The common separated value file extension are ..... A) .csv. B) .tsv. C) .txt. D) All these. Show Answer Correct Answer: A) .csv. 57. What does appending to a file do? A) Removes an item from the file. B) Changes an item in a file. C) Adds an item to the file. D) Deletes the file. Show Answer Correct Answer: C) Adds an item to the file. 58. Describe how to write data to a text file in Python. A) Use 'with open("filename.txt", "w") as file:file.write("Your data here")'. B) Use 'open("filename.txt") as file:file.write("Your data here")'. C) 'with open("filename.txt", "r") as file:file.write("Your data here")'. D) File.write("Your data here") without opening the file. Show Answer Correct Answer: A) Use 'with open("filename.txt", "w") as file:file.write("Your data here")'. 59. Which method is used to get the current position of the file handle? A) Seek(). B) Tell(). C) Whence. D) Offset. Show Answer Correct Answer: B) Tell(). 60. What will feof() return when the end of file is reached in C? A) 1. B) NULL. C) -1. D) 0. Show Answer Correct Answer: A) 1. ← 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 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