This document is a worksheet for Grade 12 Computer Science focusing on Data File Handling, containing multiple-choice questions related to file handling in Python. Topics include file opening modes, the seek() and tell() methods, and assertions regarding binary and CSV files. The worksheet is designed to test students' understanding of file operations and syntax in Python.
This document is a worksheet for Grade 12 Computer Science focusing on Data File Handling, containing multiple-choice questions related to file handling in Python. Topics include file opening modes, the seek() and tell() methods, and assertions regarding binary and CSV files. The worksheet is designed to test students' understanding of file operations and syntax in Python.
(A) seek(offset [, reference_point]) (B) seek(offset, file_object) (C) seek.file_object(offset) (D) file_object.seek(offset [, reference_point]) 2. Which functions is used to close a file in python? (A) close (B) cloose() (C) Close() (D) close() 3. Which of the file opening mode will open the file for reading and writing in binary mode? a) rb b) rb+ c) wb d) a+ 4. Which of the following python statement will bring the read pointer to 10th character from the end of a file containing 100 characters, opened for reading in binary mode. a) File.seek(10,0) b) File.seek(-10,2) c) File.seek(-10,1) d) File.seek(10,2) 5.Assertion (A): A binary file in python is used to store collection objects like lists and dictionaries that can be later retrieved in their original form using pickle module. Reasoning (R): A binary files are just like normal text files and can be read using a text editor like notepad. 6. Which of the following mode will refer to binary data? (a)r (b) w (c) + (d) b 7. The correct syntax of seek() is: (a) file_object.seek(offset [, reference_point]) (b) seek(offset [, reference_point]) (c) seek(offset, file_object) (d) seek.file_object(offset) 8. Assertion (A): CSV (Comma Separated Values) is a file format for data storage which looks like a text file. Reason (R): The information is organized with one record on each line and each field is separated by comma 9. Which file mode can be used to open a binary file in both append and read mode? a) w+ b) wb+ c) ab+ d) a+ 10. Which option correctly explains tell () method? a) tells the current position within the file. b) tells the name of file. Data File Handling Worksheet - 1 - 1 Marks Page 1 c) moves the current file position to a different location. d) it changes the file position only if allowed to do so else returns an error. 11. Assertion (A): CSV module allows to write a single record into each row in CSV file using writerow() function. Reason (R): The writerow() function creates header row in csv file by default. 12. Which of the following mode in file opening statement results or generates an error if the file does not exist? (a) r+ (b) a+ (c) w+ (d) None of the above 13.Assertion (A): A binary file stores the data in the same way as as stored in the memory. Reason (R): Binary file in python does not have line delimiter. 14. Which of the following is used to read n characters from a file object“ f1” . a)f1.read(n) b)f1(2) c)f1(read,2) d)allof the above 15. Which of the following statements correctly explain the function of seek()method? a. tells the current position with in the file. b. determines if you can move the file position or not. c. indicates that the next read or write occurs from that position in a file. d. moves the current file position to a given specified position. 16. Which of the following is not a valid mode to open a file? (a) ab (b) r+ (c) w+ (d) rw 17. The tell() function returns: (a) Number of bytes remaining to be read from the file (b) Number of bytes already read from the file (c) Number of the byte written to the file (d) Total number of bytes in the file 18. Assertion (A): CSV stands for Comma Separated Values Reason(R): CSV files are a common file format for transferring and storing data 19. Which of the following mode in file opening statement generates an error if the file does not exist? a) a+ b) r+ c) w+ d) None of these 20. tell() is a method of: a) pickle module b) csv module c) file object d) seek()
Data File Handling Worksheet - 1 - 1 Marks Page 2
21.Assertion: Pickling is the process by which a Python object is converted to a byte stream. Reason: load() method is used to write the objects in a binary file. dump() method is used to read data from a binary file 22. When the file content is to be retained , we can use the ____________ mode . . (a) r (b) w (c) a (d) w+ 23. Which of the following modes is used to open a binary file for writing (a) b (b) rb+ (c) wb (d) rb 24. Assertion (A):- If a text file already containing some text is opened in write mode the previous contents are overwritten. Reasoning (R):- When a file is opened in write mode the file pointer is present at the beginning position of the file 25. Which of the following mode in file opening statement does not overwrites the any previous content of the file? a. w+ b. r+ c. a+ d. None of the above