This quiz works best with JavaScript enabled. Home > Cbse > Class 11 > Science > Computer Science > Class 11 Computer Science Chapter 6 File Handling – Quiz 17 🏠 Homepage 📘 Download PDF Books 📕 Premium PDF Books Class 11 Computer Science Chapter 6 File Handling Quiz 17 (60 MCQs) Quiz Instructions Select an option to see the correct answer instantly. 1. Which of the following is true about the WRITEFILE command? A) It can be used without opening the file first. B) It appends the data to the end of the file by default. C) It overwrites the existing content unless the file is opened in append mode. D) It reads data from the file and writes it to another file. Show Answer Correct Answer: C) It overwrites the existing content unless the file is opened in append mode. 2. Which Tkinter widget is used to display a message to the user? A) Entry Widget. B) Canvas Widget. C) Slider. D) Message Widget. Show Answer Correct Answer: D) Message Widget. 3. What is file handling in Python? A) Procedure for creating files in Python. B) Process of working with files in Python. C) Method of manipulating data in Python. D) Technique for organizing files in Python. Show Answer Correct Answer: B) Process of working with files in Python. 4. File handling is carried out by the compiler A) TRUE. B) FALSE. C) All the above. D) None of the above. Show Answer Correct Answer: B) FALSE. 5. ..... Open the file for reading and writing. A) R. B) Wr. C) Rw. D) 'r+'. Show Answer Correct Answer: D) 'r+'. 6. By default python program save in which drive? A) C Drive. B) E Drive. C) D Drive. D) F Drive. Show Answer Correct Answer: A) C Drive. 7. What library is commonly used for handling CSV files in Python? A) Pandas. B) Numpy. C) Json. D) Csv. Show Answer Correct Answer: D) Csv. 8. Mode used for reading and writing in binary file A) W+. B) Wb+. C) Wb. D) W. Show Answer Correct Answer: B) Wb+. 9. A ..... file stores information in the form of a stream of ASCII or UNICODE characters. A) Binary File. B) Text File. C) Both Binary and Text Files. D) CSV Files. Show Answer Correct Answer: B) Text File. 10. Data stored in the files are called A) Dynamic data. B) Rough data. C) Static data. D) Persistent data. Show Answer Correct Answer: D) Persistent data. 11. Which of the following is used to write text data? A) Load(). B) Write(). C) Readlines(). D) Pickle.dump(). Show Answer Correct Answer: B) Write(). 12. Which of these will generate an error? A) MyCipher.readline(). B) MyCipher.write("writing", writing). C) MyCipher write(writing). D) MyCipher.write("writing"). Show Answer Correct Answer: B) MyCipher.write("writing", writing). 13. How do you convert a list of dictionaries to a CSV file? A) Use a text editor to manually create the CSV file. B) Convert the list of dictionaries to a JSON file instead. C) Use Python's csv module to write the list of dictionaries to a CSV file. D) Use Excel to import the list of dictionaries directly. Show Answer Correct Answer: C) Use Python's csv module to write the list of dictionaries to a CSV file. 14. What does the 'tell()' function return? A) The current position of the file pointer. B) The content of the file. C) The name of the file. D) The size of the file. Show Answer Correct Answer: A) The current position of the file pointer. 15. A data of the file is stored in A) Rom. B) Ram. C) Hard disk. D) Rim. Show Answer Correct Answer: C) Hard disk. 16. How can you append data to an existing text file? A) Open the file in read mode and write the data. B) Open the file in append mode and write the data. C) Delete the existing file and create a new one with the data. D) Open the file in write mode and overwrite the data. Show Answer Correct Answer: B) Open the file in append mode and write the data. 17. To move the file pointer 10 bytes backward from the current position, which statement would you use? A) F.seek(-10, 1). B) F.seek(10, 1). C) F.seek(-10, 0). D) F.seek(-10, 2). Show Answer Correct Answer: A) F.seek(-10, 1). 18. What function is used to read a specific number of bytes from a file in Python? A) Read bytes(). B) Read(size). C) Fetch bytes(size). D) Get bytes(size). Show Answer Correct Answer: B) Read(size). 19. Every file has its own identity associated with it. Which is known as A) D. file type. B) C. format. C) B. extension. D) -a. icon. Show Answer Correct Answer: C) B. extension. 20. JPEG stands for ..... A) Joint Photographic Exchange Group. B) Joint Protocol Exchange Group. C) Junior Photographic Experts Group. D) Joint Photographic Experts Group. Show Answer Correct Answer: D) Joint Photographic Experts Group. 21. How do you write data to a file using Fileoutputstream in Java? A) Use BufferedWriter to write data to the file. B) Use PrintWriter to write data to the file. C) Create an instance of FileOutputStream and use its write() method to write data to the file. D) Use FileReader to write data to the file. Show Answer Correct Answer: C) Create an instance of FileOutputStream and use its write() method to write data to the file. 22. What would be the size of the following union declaration? (Assuming size of double = 8, size of int = 4, size of char = 1) #include union uTemp { double a; int b[10]; char c; }u; A) 8. B) 4. C) 40. D) 80. Show Answer Correct Answer: C) 40. 23. Str = "CBSE Class XII Python Examination 2024"Filein = open("myfile.txt", "w+")print("Name of the file: ", Filein.name)Filein.writelines(Str)Filein.seek(0, 0)for line in Filein:print(line)Filein.close() A) CBSE Class XII python Examination 2024. B) CBSE Class XII Python Examination 2024. C) Name of the file:myfile.txtCBSE Class XII Python Examination 2024. D) None. Show Answer Correct Answer: C) Name of the file:myfile.txtCBSE Class XII Python Examination 2024. 24. Why do we save files? A) To create digital documents. B) To keep data permanently. C) To keep data temporarily. D) To store large data. Show Answer Correct Answer: B) To keep data permanently. 25. What is the return type of the length() method in the File class? A) Int. B) Long. C) Double. D) Float. Show Answer Correct Answer: B) Long. 26. What is a file in the context of data storage? A) A hardware component of a computer. B) A collection of unrelated data. C) A collection of related data stored in a particular area on the disk. D) A type of software application. Show Answer Correct Answer: C) A collection of related data stored in a particular area on the disk. 27. When opening a file for writing using OPENFILE "data.txt" FOR WRITE, what happens if "data.txt" already exists? A) The file is deleted and a new empty file is created. B) The file cannot be opened unless it is empty. C) Data will be appended to the existing data. D) The file is opened normally with no changes to existing data. Show Answer Correct Answer: A) The file is deleted and a new empty file is created. 28. Files don't need to be closed when using file handling in programming A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: B) False. 29. Write the output of the following:>>> f = open("test.txt", "w") >>> f.closed >>> f.close() >>> f.closed A) No Yes. B) False True. C) True False. D) Yes No. Show Answer Correct Answer: B) False True. 30. What is the purpose of the 'seek' method in Python file handling? A) To delete the file from the system. B) To move the file pointer to a specific position within the file. C) To read the entire contents of the file. D) To close the file after reading or writing. Show Answer Correct Answer: B) To move the file pointer to a specific position within the file. 31. An interrupt or forced disruption that occurs when a program is run or executed is termed as A) Exception. B) Runtime error. C) Logical error. D) Compile time error. Show Answer Correct Answer: A) Exception. 32. What is the output of this program? #include int main(){typedef struct tag {char str[10];int a;} tag;tag h1, h2 = { "IHelp", 10 };h1 = h2;h1.str[1] = 'h';printf("%s, %d", h1.str, h1.a);return 0;} A) No Error, No output. B) Error. C) IHelp 10. D) Ihelp 10. Show Answer Correct Answer: D) Ihelp 10. 33. What is the primary function of fopen() in C programming? A) To open a file for reading. B) To allocate memory dynamically. C) To close a file. D) To delete a file. Show Answer Correct Answer: A) To open a file for reading. 34. What will malloc() return if it fails to allocate memory? A) 1. B) 0. C) NULL. D) -1. Show Answer Correct Answer: C) NULL. 35. Sizeof(struct) gives: A) Only sum of all fields. B) Always equal to sum. C) May be bigger due to padding. D) Always 4 bytes. Show Answer Correct Answer: C) May be bigger due to padding. 36. What is one way to avoid accidental changes to a file? A) Open the file in delete mode. B) Open the file in write mode. C) Open the file in edit mode. D) Open the file in read mode. Show Answer Correct Answer: D) Open the file in read mode. 37. Which is more secure for sensitive data? A) Text File. B) Binary File. C) CSV File. D) None of these. Show Answer Correct Answer: B) Binary File. 38. Explain the process of reading a file line by line in Python. A) With open('file.txt', 'r') as file:for line in file:print(line). B) For line in file.readlines():. C) File.read():. D) Open('file.txt', 'r').readlines():. Show Answer Correct Answer: A) With open('file.txt', 'r') as file:for line in file:print(line). 39. Fp.readlines() returns data as a A) List. B) Tuple. C) String. D) Dictionary. Show Answer Correct Answer: A) List. 40. What does the function fgets do in file handling? A) Writes a string of text to a file. B) Closes an open file. C) Reads characters from a file and puts them in a buffer. D) Checks if the file has reached the end. Show Answer Correct Answer: C) Reads characters from a file and puts them in a buffer. 41. What does the abs() function in Python do? A) Returns the absolute difference between two numbers. B) Returns the absolute value of a number. C) Calculates the average of a sequence of numbers. D) Converts a value to an absolute integer. Show Answer Correct Answer: B) Returns the absolute value of a number. 42. What is the purpose of defining a function in Python? A) To create a new data type in Python. B) To increase the execution speed of the program. C) To encapsulate reusable code and improve organization. D) To define global variables for the entire program. Show Answer Correct Answer: C) To encapsulate reusable code and improve organization. 43. What is the prerequisite knowledge before learning file handling? A) Experience with databases. B) Basic knowledge of algorithms and variables. C) Understanding of file systems. D) Knowledge of network protocols. Show Answer Correct Answer: B) Basic knowledge of algorithms and variables. 44. CSV files are known as flat text files. Is the statement true or false. A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: A) True. 45. Name the module that has to be imported to write a binary file. A) Csv module. B) Pickle module. C) Unpickle module. D) Random module. Show Answer Correct Answer: B) Pickle module. 46. What does this code myfile=open( "taxes.txt" ) perform A) Opens the taxes.txt in default read mode. B) Opens the taxes.txt in default write mode. C) Opens the taxes.txt in default append mode. D) Opens the taxes.txt in default read and write mode. Show Answer Correct Answer: A) Opens the taxes.txt in default read mode. 47. Which of the following is a function of the pickle module? A) Load(). B) Reader(). C) Read(). D) Writer(). Show Answer Correct Answer: A) Load(). 48. What is the mode 'w' used for when opening a file? A) Execute. B) Write. C) Read. D) Append. Show Answer Correct Answer: B) Write. 49. How can you check if a path is absolute using pathlib? A) Using the is absolute() method. B) Using the is relative() method. C) All the above. D) None of the above. Show Answer Correct Answer: A) Using the is absolute() method. 50. Which of the following classes can be used for both reading and writing to a file in C++? A) 'fstream'. B) 'ofstream'. C) 'ifstream'. D) 'istream'. Show Answer Correct Answer: A) 'fstream'. 51. What is the output of the program that reads and writes using binary mode? A) Data written to file successfully. B) Error opening file. C) File not found. D) Name:John Doe, Age:30. Show Answer Correct Answer: D) Name:John Doe, Age:30. 52. Choose an exception if attempt to divide number by zeroint number = 89 / 0;System.out.println("The answer is '' + number); A) NullPointerException. B) ArrayIndexOutOfBoundException. C) ArithmeticException. D) NumberFormatException. Show Answer Correct Answer: C) ArithmeticException. 53. What does the method returns? A) Str. B) List of integers. C) A list of lines. D) List of single characters. Show Answer Correct Answer: C) A list of lines. 54. What is used to store values in variables A) Pram. B) Rom. C) Ram. D) Prom. Show Answer Correct Answer: C) Ram. 55. What is the output of the following program? import csv d=csv.reader(open ("city.csv'))next(d)for row in d:print(row) if the file called "city.csv" contain the following detailschennai, mylaporemumbai, andheri A) Chennai, mylapore. B) Mumbai, andheri. C) Chennaimumbai. D) Chennai, mylaporemumbai, andheri. Show Answer Correct Answer: B) Mumbai, andheri. 56. To append text to an existing file without erasing its contents, which mode should you use? A) "w+". B) "wb". C) "a". D) "r+". Show Answer Correct Answer: C) "a". 57. In which mode, should we open the file to add data into the file? A) Write. B) W. C) R. D) A. Show Answer Correct Answer: D) A. 58. How can you write data to a file in Python? A) Use 'with open('filename.txt', 'x') as file:file.write('data')' to write. B) Use 'with open("filename.txt", "w") as file:file.write("data")'. C) Use 'open('filename.txt', 'r') as file:file.write('data')'. D) Write 'data' to file using 'open('filename.txt', 'a')' method. Show Answer Correct Answer: B) Use 'with open("filename.txt", "w") as file:file.write("data")'. 59. In this program, what does the function myAdd do?def myAdd(a, b) return a+b A) Subtracts two numbers. B) Adds two numbers. C) Multiplies two numbers. D) Crashes the program. Show Answer Correct Answer: D) Crashes the program. 60. Serial Files are organized by time. A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: A) True. ← 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