This quiz works best with JavaScript enabled. Home > Cbse > Class 11 > Science > Computer Science > Class 11 Computer Science Chapter 6 File Handling – Quiz 25 🏠 Homepage 📘 Download PDF Books 📕 Premium PDF Books Class 11 Computer Science Chapter 6 File Handling Quiz 25 (60 MCQs) Quiz Instructions Select an option to see the correct answer instantly. 1. What is the purpose of closing a file in Python? A) Closing a file in Python is used to delete the file. B) Closing a file in Python is not necessary. C) Closing a file in Python is only required for text files. D) The purpose of closing a file in Python is to release resources and save changes. Show Answer Correct Answer: D) The purpose of closing a file in Python is to release resources and save changes. 2. Pri ispisu primjerice "Hello world" u datoteku pozdrav.txt preko objekta ispis, pravilno je zapisati: A) Txt<<"Hello world"< B) Ispis<<"Hello world"< C) Pozdrav<<"Hello world"< D) Cout<<"Hello world"< Show Answer Correct Answer: B) Ispis<<"Hello world"< 3. Which stream used to read data from a source, it may be a file, an array, peripheral device or socket? A) InputStream. B) OutputStream. C) Input/OutputStream. D) None of the above. Show Answer Correct Answer: A) InputStream. 4. What is the output of the length() method if the file is empty? A) -1. B) 0. C) Undefined. D) Null. Show Answer Correct Answer: B) 0. 5. Which is called as Direct Access? A) Sequential Access. B) Random Access. C) Both a and b. D) None of the above. Show Answer Correct Answer: B) Random Access. 6. Predict the output of above program. Assume that the size of an integer is 4 bytes and size of character is 1 byte. Also assume that there is no alignment needed.union test{ int x; char arr[4]; int y;};int main(){ union test t; t.x = 0; t.arr[1] ='G'; printf("%s", t.arr); return 0;} A) Garbage character followed by 'G'. B) Compiler Error. C) Nothing is printed. D) Garbage character followed by 'G', followed by more garbage characters. Show Answer Correct Answer: C) Nothing is printed. 7. A class which is capable of creating files, writing to files, reading from data files is called A) Iostream. B) Ifstream. C) Fstream. D) Ofstream. Show Answer Correct Answer: C) Fstream. 8. Which mode is taken as default mode for opening a File in Python? A) R. B) A. C) W. D) None. Show Answer Correct Answer: A) R. 9. Which of the following method is used to read from file? A) Get(). B) Scanf(). C) Read(). D) ReadFile(). Show Answer Correct Answer: C) Read(). 10. The output of executing string.ascii ..... letters can also be achieved by: A) String.ascii lowercase+string.ascii uppercase. B) String.lowercase string.uppercase. C) String.letters. D) String.ascii lowercase string.digits. Show Answer Correct Answer: A) String.ascii lowercase+string.ascii uppercase. 11. Which Tkinter component is used to manage the arrangement of widgets? A) Slider. B) Layout Management. C) Canvas Widget. D) Message Widget. Show Answer Correct Answer: B) Layout Management. 12. During a class project, Reyansh and Tanisha were discussing how to handle data files. They wondered what the default delimiter is when using the csv module in Python. A) ,. B) ;. C) |. D) Tab. Show Answer Correct Answer: A) ,. 13. Which method is used to write multiple lines to a file? A) File.addlines(). B) File.write(). C) File.append(). D) File.writelines(). Show Answer Correct Answer: D) File.writelines(). 14. Sequential Access will be slower when compared to random access? State True or False A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: A) True. 15. Which file mode ensures new data is always added at end without overwriting? A) "r+". B) "w". C) "a". D) "w+". Show Answer Correct Answer: C) "a". 16. Mana yang berarti menulis ke file? A) Ios::out. B) Ios::trunc. C) Ios::in. D) Ios::app. Show Answer Correct Answer: A) Ios::out. 17. What does the 'os.rmdir()' function do? A) Renames a file. B) Creates a new directory. C) Removes a directory. D) Removes a file. Show Answer Correct Answer: C) Removes a directory. 18. Which of the following is a valid way to check if a path exists? A) Os.path.isfile(path). B) Os.path.isdir(path). C) Os.path.exists(path). D) Path.exists(). Show Answer Correct Answer: C) Os.path.exists(path). 19. ..... files are used to store binary data(machine code) such as images, video and audio files A) Binary. B) Text. C) CSV. D) All of the above. Show Answer Correct Answer: A) Binary. 20. Identify the error in the following code. 1. f = open ("workfile.txt', 'r+') 2. f.write('0123456789abcdef') 3. f.write('xyz8466') 4. f.close() 5. f.seek (0) 6. f.read() A) Line 2. B) Line 1. C) Line 6. D) Line 5. Show Answer Correct Answer: C) Line 6. 21. What should you do if the data read from the file does not match the search criteria? A) Rewrite the data correctly. B) Delete the data from the file. C) Stop the program. D) Continue reading until the end of the file. Show Answer Correct Answer: D) Continue reading until the end of the file. 22. Which function is used to dynamically allocate memory in C? A) Malloc(). B) Allocate(). C) New(). D) Calloc(). Show Answer Correct Answer: A) Malloc(). 23. The unexpected event happened during program execution should be handled by A) ASSERTION. B) EXTRAORDINARY. C) EXPERIMENT. D) EXCEPTION. Show Answer Correct Answer: D) EXCEPTION. 24. What are the types of files mentioned in the lesson plan? A) Text. B) Binary. C) Both. D) None. Show Answer Correct Answer: C) Both. 25. List and describe different types of directory structures. A) 1. Flat Structure, 2. Hierarchical Structure, 3. Networked Structure, 4. Database Structure. B) Circular Structure. C) Linear Structure. D) Segmented Structure. Show Answer Correct Answer: A) 1. Flat Structure, 2. Hierarchical Structure, 3. Networked Structure, 4. Database Structure. 26. How do you convert user input to a float safely? A) Use try-except to catch ValueError when converting input to float. B) Use print statements to debug the conversion process. C) Convert input to an integer before converting to float. D) Always assume the input is a valid float. Show Answer Correct Answer: A) Use try-except to catch ValueError when converting input to float. 27. What is the correct definition for a VARIABLE? A) A changeable value, such as a score in a computer game. B) A value that cannot be changed. C) All the above. D) None of the above. Show Answer Correct Answer: A) A changeable value, such as a score in a computer game. 28. Given the following file opened as song ..... file:I can't write one song that's not about youCan't drink without thinkin' about youIs it too late to tell you thatEverything means nothing if I can't have you?What is the result ofprint(song ..... file.read(4))? A) I ca. B) I c. C) YouIs it too late to tell you thatEverything means nothing if I can't have you?. D) I canI cI can't write one song that's not about youCan't drink without thinkin' about. Show Answer Correct Answer: A) I ca. 29. What does file handling in Python allow you to do? A) Access and modify files on your computer. B) Create new programming languages. C) Design websites. D) Play video games. Show Answer Correct Answer: A) Access and modify files on your computer. 30. Which of the following error is returned when we try to open a file in read mode which does not exist? A) FileNotFoundError. B) FileFoundError. C) FileNotExistError. D) None of the above. Show Answer Correct Answer: A) FileNotFoundError. 31. File can be 'looked at' by the program but not changed. Error if the file doesn't already exist. A) Read. B) Append. C) Write. D) None of the above. Show Answer Correct Answer: A) Read. 32. Assertion:'Pickling' is the process whereby a Python object hierarchy is converted into a byte-streams. Reason:A binary file works with byte-streams. A) Both A and R are true and R is the correct explanation of A. B) Both A and R are true and R is not the correct explanation of A. C) A is true but R is false (or partly true). D) A is false (or partly true) but R is true. Show Answer Correct Answer: A) Both A and R are true and R is the correct explanation of A. 33. Which function in pseudocode is used to write data to a file? A) 'APPEND data TO file'. B) 'WRITE TO file'. C) 'WRITE line TO file'. D) 'WRITE data TO file'. Show Answer Correct Answer: D) 'WRITE data TO file'. 34. What is the importance of closing a file after file handling operations in Python? A) It prevents data loss. B) It frees up resources. C) It improves file security. D) It speeds up file access. Show Answer Correct Answer: B) It frees up resources. 35. Explain how to read a specific number of bytes from a binary file. A) Use the read method without specifying a byte count. B) Open the file in text mode and use the write method. C) Open the file in binary mode and use the read method with the desired byte count. D) Read the entire file into memory before accessing specific bytes. Show Answer Correct Answer: C) Open the file in binary mode and use the read method with the desired byte count. 36. Predict the output of the following program#include int main(){ register int i = 10; int *ptr = &i; printf("%d ", *ptr); return 0; } A) Runtime error. B) 10. C) Compiler error. D) 0. Show Answer Correct Answer: C) Compiler error. 37. Which file is not binary file? A) Student.csv. B) Student.exe. C) Student.mp4. D) Student.jpeg. Show Answer Correct Answer: A) Student.csv. 38. What are the different access modes available in Python for file handling? A) 'r', 'w', 'a', 'r+', 'w+', 'a+'. B) Y. C) X. D) Z. Show Answer Correct Answer: A) 'r', 'w', 'a', 'r+', 'w+', 'a+'. 39. How can you read the next line of a file using streaming? A) Using the 'write()' function. B) Using the 'read()' function. C) Using the 'close()' function. D) Using the 'next()' function. Show Answer Correct Answer: D) Using the 'next()' function. 40. Apa nilai default parameter dtype yang dikembalikan oleh fungsi numpy.loadtxt()? A) Float. B) Integer. C) Object. D) String. Show Answer Correct Answer: A) Float. 41. What does fread() do? A) Deletes a file. B) Reads data from a file. C) Checks for file errors. D) Writes data to a file. Show Answer Correct Answer: B) Reads data from a file. 42. What should a program do to prevent errors when working with files? A) Check if the file exists before attempting to open it. B) Always delete the file before writing to it. C) All the above. D) None of the above. Show Answer Correct Answer: A) Check if the file exists before attempting to open it. 43. Which of the following file modes allows both reading and writing without overwriting? A) W. B) R. C) R+. D) A. Show Answer Correct Answer: C) R+. 44. What will be the output of the following C code? #include struct student { int no; char name[20]; }; void main() { student s; s.no = 8; printf("%d", s.no); } A) Junk. B) Compile time error. C) Nothing. D) 8. Show Answer Correct Answer: B) Compile time error. 45. Which methods will create the file if it is not found? A) Read. B) Write. C) Append. D) Write and append. Show Answer Correct Answer: D) Write and append. 46. Name and explain at least three CPU scheduling algorithms. A) Shortest Remaining Time (SRT). B) Multilevel Queue Scheduling (MQS). C) Priority Scheduling (PS). D) 1) First-Come, First-Served (FCFS), 2) Shortest Job Next (SJN), 3) Round Robin (RR). Show Answer Correct Answer: D) 1) First-Come, First-Served (FCFS), 2) Shortest Job Next (SJN), 3) Round Robin (RR). 47. Which mode allows us to add data to an existing file?file =open("poem.txt", " ..... ") A) A. B) R. C) X. D) W. Show Answer Correct Answer: A) A. 48. Apa fungsi dari fopen dalam pemrograman C? A) Membaca data dari file. B) Membuka file. C) Menulis data ke file. D) Menutup file. Show Answer Correct Answer: B) Membuka file. 49. What is the role of next() when Rashil is working with CSV files in Python? A) Next() is used to skip the header row in CSV files. B) Next() is used to convert CSV data into a dictionary. C) Next() is used to write data to a new CSV file. D) Next() is used to read the entire CSV file at once. Show Answer Correct Answer: A) Next() is used to skip the header row in CSV files. 50. Dump function is used to ..... A) Write data in file. B) Delete the content of file. C) Read data from file. D) Destroy the file. Show Answer Correct Answer: A) Write data in file. 51. What is the file object's attribute to get file name? A) File. B) Getname. C) Filename. D) Name. Show Answer Correct Answer: D) Name. 52. An absolute path name begins at the A) Current directory. B) Stem. C) Leaf. D) Root. Show Answer Correct Answer: D) Root. 53. Which of these method of FileReader class is used to read characters from a file? A) GetInteger(). B) Read(). C) Scanf(). D) Get(). Show Answer Correct Answer: B) Read(). 54. 'w+' mode will ..... A) First write the file by deleting the contents of the existing file, if the file exists. B) First read the file and then write the contents by deleting its contents, if the file exists. C) First write and then read the file contents, by deleting the contents of the file if the file exists. D) First read and then write the contents, by deleting the contents of the file if the file exists. Show Answer Correct Answer: C) First write and then read the file contents, by deleting the contents of the file if the file exists. 55. What module provides access to some variables used or maintained by the interpreter? A) Path. B) Os. C) Io. D) Sys. Show Answer Correct Answer: D) Sys. 56. Which mode is used to open a text file for reading? A) R. B) Wb. C) A. D) W. Show Answer Correct Answer: A) R. 57. What is the significance of using 'with' when opening a file? A) It prevents any errors from occurring while writing. B) It ensures proper resource management by automatically closing the file. C) It allows for faster file access during reading. D) It enables multiple files to be opened simultaneously. Show Answer Correct Answer: B) It ensures proper resource management by automatically closing the file. 58. Which of the following is a valid way to read a file line by line? A) All of the above. B) File.readline(). C) File.readlines(). D) File.read(). Show Answer Correct Answer: A) All of the above. 59. What is an array? A) The name of a variable. B) A collection of variables of the same type. C) It's like an x-ray, but using a beams. D) None of the above. Show Answer Correct Answer: B) A collection of variables of the same type. 60. What does the 'write()' method do when called on a file object? A) Closes the file. B) Reads data from the file. C) Opens the file. D) Writes data to the file. Show Answer Correct Answer: D) Writes data to the file. ← 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