Download Computer Science – Data File Handling and more Exams Computer science in PDF only on Docsity! Name of the Chapter- DATA FILE HANDLING Question No Question Content Learning Objective(if Provided) Q1. Suppose content of ‘mytext.txt’ file is: What will be the output of the following code? file = open(“mytext.txt”, ‘r’) txt = file.read() print(file.read(10)) (A) The key to (B) obstacles. (C) Error (D No Output Knowledge Q2. Consider the following directory structure: There are three directories under root directory ‘Admin’. The current working directory is Final. Identify the relative path name for file ‘Result1.xlsx’. (A) .\Result1.xlsx (B) Admin\Final\First Term\Result1.xlsx (C) ..\First Term\Result1.xlsx (D) First Term\Result1.xlsx Application Q3. Which of the following statements is correct regarding file access modes? (A) In ‘r’ mode, we can read and write data from/in the file. (B) In ‘a’ mode, the existing data will be over-written if the file exists. Understanding (C) In ‘w’ mode, the data in the file is retained and new data will be appended to the end. (D) In ‘a+’ mode, both reading and writing operations can take place and new data is appended to the end of the existing file. Q4. Consider a statement fileobj = open(“myblog.txt”, ‘r’) Which of the following options can be used to print the last line of a text file ‘myblog.txt’? (A) print(fileobj.readlines() -1) (B) disp = fileobj.readlines() print(disp[-1]) (C) print(fileobj.readlines(-1)) (D) print(fileobj.read(-1)) Understanding Q5. Which of the following statements is used to open a text file to add new contents at the end of the already existing text file named ‘mydiary.txt’? (i) with open(“’mydiary.txt”, ‘w’) as fileobj: (ii) fileobj = open(“mydiary.txt”, ‘a’) (iii) with open(“mydiary.txt”,’a’) as fileobj: (iv) with open(“mydiary”, ‘r+’) as fileobj: (A) Only (i) (B) Only (ii) (C) Both (ii) and (iii) (D) Both (i) and (iv) Understanding Q6. “The information is stored in machine-readable format and pickle module is used for reading and writing data from/in the file.” Identify the type of file discussed in the above lines? (A) Text files (B) CSV files (C) Binary file (D) All of the above Understanding Q7. Assume that you are writing in a text file; now you want to identify where the cursor is currently at in the file. Which function will you use for the same? (A) seek() (B) hide() (C) tell() (D) type() Knowledge the end. (C) In w+ mode, the pointer is initially placed at the beginning of the file and for r+, the pointer is placed at the end. (D) Depends on the operating system. Q16 Information stored on a storage device with a specific name. is called a A. Array B. Dictionary C. file D. tuple Q17 EOL stands for A. End of Lines B. End Of Line C. End Of List D. End Of Location Q18 Which of the following file types allows to store large data files in the computer memory? A. Text Files B. Binary Files C. CSV Files D. None of these Q19 Which of the following functions transfer the data to file before closing the file? A. flush() B. close() C. open() D. fflush() Q20 Which of the following is not a known file type? A. csv B. pdf C. txt D. txp Q21 Which of the following not a valid file extension for file student? A. student.txt B. student.cvc C. student.dat D. student.pdf Q22 Which of the following is not a correct statement for binary files? A. Easy for carrying data into buffer B. Much faster than other file systems C. Every line ends with new line character ‘\n’ D. Characters translation is not required Q23 Which of the following file types can be opened with notepad as well as ms excel? A. Text Files B. CSV Files C. Binary Files D. None of these Q24 Which of the following format of files can be created programmatically through python to store some data? A. Pdf file B. Audio file C. Binary file D. Video file Q25 Which file can open in any text editor and is in human readable form? A. Binary files B. Text files C. Data files D. d. Video files Q26 _________ is a file format which stores records separated by comma. A. .tsv B. .csv C. .py D. .bin Q27 The CSV files can be operated by _______software. A. Spreadsheet B. Notepad C. MS Excel D. All of the above Q28 Which of the following parameter needs to be added with open function to avoid blank row followed file each row in CSV file? A. delimiter B. newline C. writer, delimiter D. file object Q29 12. Default EOL character in Python. A. ‘\n’ B. ‘\r’ C. ‘’ D. ‘\t’ Q30 Trying to open a binary file using a text editor will show: A. Garbage values B. ASCII values C. Binary character D. Unicodes Q31 Choose the correct syntax to open a file in write mode. (A) f.open(“file.txt”,’w’) (B) f = open(“file.txt”) (C) f = open(“file.txt”,’w’) (D) f = open(“file.txt”, ‘r’) KNOWLEDGE AND UNDERSTANDING Q32 Choose the correct syntax to open a file in append mode. (A) with open(“file.txt”, “a”) as f : (B) with open(“file.txt”) as “f” (C) with open(“file.txt”, “a”) as f (D) with open(“file.txt”, “w”) as f : KNOWLEDGE AND UNDERSTANDING Q33 Which of the following is not a valid file access mode? (A) a+ (B) r (C) w (D) b+ KNOWLEDGE AND UNDERSTANDING Q34 Choose the correct syntax to close a file. (A) f.closed KNOWLEDGE AND UNDERSTANDING (C) string 1 of list lines will overwrite string 2 of list lines in the file ‘readme.txt’. (D) string 2 of list lines will overwrite string 1 of list lines in the file ‘readme.txt’. Q46 What are the file types in Python? (A) Text File (B) TSV File (C) CSV File (D) All of the above Understanding Q47. Which command is used to open a text file in Python in reading mode? (A) F = open( ) (B) F = open(“Data.Txt”,”w”) (C) F = open(“Data.Txt,”r”) (D) All of the Above Analysis Q48 What is the use of File Object? (A) File Object Serves as a link to a file (B) File Objects are used to read and write data to the file (C) A file Object is a reference to a file on disk (D) All of the above Knowledge Q49 Which is the default mode to open a file? (A) read mode (B) r+ mode (C) write mode (D) w+ mode Knowledge Q50 Which mode creates a new file, when open file ? (A) w+ mode (B) a mode (C) a+ mode (D) All of the above Understanding Q51 Which function is used to read the contents from a file? (A) read ( ) (B) write ( ) (C) close ( ) (D) None of these Knowledge Q52 Which of the following command is used to open a file “C:\\Data.txt for writing as well as reading mode ? (A) f = open(“c:\\pat.txt”,”w”) (B) f = open(“c:\\pat.txt”,”wb”) (C) f = open(“c:\\pat.txt”,”w+”) (D) f = open(“c:\\pat.txt”,”wb+”) Application Q53 Which function is used to write a list of strings in a file? (A) writeline ( ) (B) writelines ( ) (C) writelist ( ) (D) writefulline ( ) Understanding Q54 When open a file in append mode, by default new data can be added at the? (A) Beginning of the file (B) End of the file (C) At the middle of the file (D) All of the above Analysis Q55. Find the output of the following code – fp = open("sample.txt", "r") fp.read(8) print(fp.tell()) fp.close() (A) 0 Application (B) 7 (C) 8 (D) 9 Q56 What will be the output of the following code if content of the file “smile.txt” is: Smiling is infectious, You catch it like the flu. When someone smiled at me today, I started smiling too. file=open(“smile.txt”) contents=file. read() print(file. read (7)) (A) Smiling (B) Smilin (C) ng too. (D) No output application Q57 If the content of the file “wish.txt” is – “Happy”, then what will be the content of the file after executing the following statements – f=open (“wish.txt”, ‘w’) f. write(“Birthday”) f. close()? (A) Happy Birthday (B) HappyBirthday (C) Happy (D) Birthday Application Q58 Consider a code: Fileobj = open("story.txt", 'a') x= 200 a= Fileobj.write(x) Creation Q62 The _____ file mode is used when user want to write data into Text file. (A) rb (B) b (C) b+ (D) w UNDERSTANDING KNOWLEDGE Q63 The _____ file mode is used when user want to read and write data into Text file. (A) rb (B) b (C) r+ (D) w UNDERSTANDING KNOWLEDGE Q64 The _____ file mode is used when user want to write and read data into Text file. (A) rb (B) w+ (C) r+ (D) w UNDERSTANDING KNOWLEDGE Q65 The _____ file mode is used when user want to append data into Text file. (A) rb (B) w+ (C) r+ (D) a UNDERSTANDING KNOWLEDGE Q66 Name the function to read from Text file. UNDERSTANDING (A) read() (B) csv.reader() (C) csv.read() (D) reader() KNOWLEDGE ANALYSIS Q67 The correct syntax to read from Text file is__________ (A) <filehandle>.read() (B) read.(filehandle) (C) read(filehanle).txt (D) None of the above UNDERSTANDING KNOWLEDGE ANALYSIS Q68 The correct syntax to reads a line of input from Text file is__________ (A) <filehandle>.read() (B) readline.(filehandle) (C) read(filehanle).txt (D) <filehandle>.readline() UNDERSTANDING KNOWLEDGE ANALYSIS Q69 The correct syntax to reads all lines of input from Text file and returns them in a list is __________ (A) <filehandle>.readlines() (B) readline.(filehandle) (C) read(filehanle).txt (D) <filehandle>.readline() UNDERSTANDING KNOWLEDGE ANALYSIS Q70 In which file, delimiters are used for line and translations occur? (A) Text file (B) Binary file (C) Both are correct (D) None of the above UNDERSTANDING KNOWLEDGE ANALYSIS Q71 observe the following code and answer the follow f1=open("mydata","a") ______#blank1 f1.close() what type of file is mydata? (A) Text file (B) Binary file (C) Both are correct (D) None of the above UNDERSTANDING KNOWLEDGE ANALYSIS Q72 observe the following code and answer the follow f1=open("mydata","a") ______#blank1 f1.close() Fill in the blank1 with correct statement to write "abc" in the file "mydata" (A) f1.write(“abc”) (B) write(abc) (C) write.f1(abc) (D) None of the above UNDERSTANDING KNOWLEDGE ANALYSIS Q73 In which of the following file modes the existing data of the file will not be lost? (A) ab and a+b mode (B) r mode (C) w mode (D) None of the above UNDERSTANDING KNOWLEDGE ANALYSIS c) file position remains unchanged d) error Q87 readlines() method return _________ a. String b. List c. Dictionary d. Tuple Knowledge Q88 Which of the following method is used to read a specified number of bytes of data from a data file. a. read( ) b. read(n) c. readlines( ) d. reading(n) Knowledge Q89 Write the output of the following: f=open("test.txt","w+") f.write("File-Handling") f.seek(0) a=f.read(5) print(a) a. File- b. File c. File-H d. No Output Understanding Q90 Write the output of the following: f=open("test.txt","w+") f.write("FileHandling") f.seek(0) a=f.read(-1) print(a) a. File b. Handling c. FileHandling d. No Output Understanding Q91 Soumya is learning to use word processing software for the first time. She creates a file with some text formatting features using notepad. What type of file is she working on? A. Text file B. CSV file Knowledge C. Binary file D. All of the above Q92 To read the remaining lines of the file from a file object F, we use A. F.read B. F.read() C. F.readlines() D. F.readline() Knowledge Q93 Which statement is used to retrieve the current position within file? A. seek() B. tell() C. loc() D. pos() Knowledge Q94 In text file each line is terminated by a special character called ? A. EOL B. END C. Full Stop D. EOF Knowledge Q95 What error is returned by following statement, if file “try.txt” does not exist? f = open(“try.txt”) A. Not Found B. File Not Found Error C. File Does Not Exist D. No Error Knowledge & understanding Q96 To open a file c:/story.txt reading we use_________________ A. F=open(‘c:/story.txt’,r) B. F=open(‘c://story.txt’,r) C. F=open(‘c:\story.txt’,r) D. F=open(‘c:\\story.txt’,r) Knowledge & understanding Q97 Another name of file object is A. File handle B. File name C. No another name D. File Knowledge Q98 Name the module required for Text Files knowledge A. Pickle B. CSV C. String D. No module required Q99 To open a file Myfile.txt for appending , we can use A. F=open("Myfile.txt","a") B. F=open(“Myfile.txt","w+") C. F=open(r"d:\Myfolder\Myfile.txt","w") D. F=open("Myfile.txt","w") understanding Q100 To read the 02 characters of the file from a file object F, we use A. F.read(2) B. F.read() C. F.readlines() D. F.readline() Knowledge & Application Q101 To read the next line of the file from a file object F, we use A. F.read(2) B. F.read() C. F.readlines() D. F.readline() Knowledge & Application Q102 The readlines() method returns A. String B. A List of integers C. A list of characters D. A List of Lines Knowledge Q103 Assume you are reading from a text file from the beginning and you have read 10 characters. Now you want to start reading from the 50th character from the beginning. Which function will you use to do the same? A. seek(50,1) B. seek(50,2) C. seek(40,0) D. seek(50,0) Knowledge & Application Q104 Consider the content of the file ‘Story.txt’ What is the output of the following code? Knowledge , understanding & application print(f.tell()) (A) 605 (B) 506 (C) 065 (D)560 Q112 What does the readline() method returns? (A)str (B) a list of lines (C) list of single characters (D) list of integers Understanding Q113 How do you change the file position to an offset value from the start? (A)fp.seek(offset, 0) (B) fp.seek(offset, 1) (C) fp.seek(offset, 2) (D)none of the mentioned Analysis Q114 Which statement will return one line from a file (file object is ‘f’) as string? (A)f.readlines( ) (B) f.readline( ) (C) f.read( ) (D)f.line(1) Understanding Q115 Which function is used to read data from Text File? (A)read( ) (B) writelines( ) (C) pickle( ) (D)dump( ) Understanding Q116 The syntax of seek() is: file_object.seek(offset [, reference_point]) What is reference_point indicate? (A)reference_point indicates the starting position of the file object (B) reference_point indicates the ending position of the file object (C) reference_point indicates the current position of the file object (D)All of the above. Analysis Q117 The syntax of seek() is:file_object.seek(offset [, reference_point]) What all values can be given as a reference point? (A)1 (B) 2 (C) 0 (D)All of the above Application Q118 What will be the output of the following code snippet? f = None for i in range (5): with open("myfile.txt", "w") as f: if i > 2: break print (f.closed) (A)Runtime Error (B) True (C) False (D)Hello world Analysis Q119 What happens if no arguments are passed to the seek function? (A)file position is set to the start of file (B) file position is set to the end of file (C) file position remains unchanged (D)error Analysis Q120 How do you change the file position to an offset value from the current position? (A)fp.seek(offset, 0) (B) fp.seek(offset, 1) (C) fp.seek(offset, 2) (D)none of the mentioned Application Q121 What are the file types in Python? (A) Text File (B) Binary File (C) CSV File (D) All of the above Understanding Q122 What are the examples of Binary file in Python? (A) .jpeg (B) .gif (C) .bmp (D) All of the above Understanding Q123 Which command is used to open a binary file in Python in reading mode? (A) F = open(“Data.dat”,”ab”) (B) F = open(“Data.dat”,”wb”) (C) F = open(“Data.dat, “rb”) (D) All of the Above Analysis Q134. When we open a binary file in write mode the file pointer is present at the: (A)End of the file (B)Beginning of the file (C)Anywhere in between the file (D)Second line of the file Q135. What can be taken as a parameter in the open( ) function of a binary file? (A) File name (B) Access mode (C) Both of the above (D) None of the above Q136 A Binary file stores information in the form of __________ . (A) A stream of bytes (B) A stream of ASCII characters (C) A stream of UNICODE characters (D) All of the above Knowledge Q37 Which of the following file mode will refer to the BINARY mode? (A) binary (B) b (C) bin (D) w Understanding Q138 The process of converting the structure to a byte stream before writing to the file is known as ______. (A) Pickling (B) Unpickling (C) Conversion Knowledge (D) Changing Q139 Which of the following is not a correct statement for binary files? (A) Easy for carrying data into buffer (B) Much faster than other file systems (C) Characters translation is not required (D) Every line ends with new line character ‘\n’ Evaluation Q140 Which of the following file mode open a file for reading and writing both in the binary file? (A) r (B) rb (C) rb+ (D) rwb Knowledge Q141 Which of the following file mode open a file for reading and writing both in the binary file? (A) wb (B) wb+ (C) w+b (D) B & C both Knowledge Q142 Which of the following file mode opens a file for append or read a binary file and moves the files pointer at the end of the file if the file already exist otherwise create a new file? (A) a (B) ab (C) ab+ (D) a+ Knowledge Q143 Which is not the valid mode for binary files? (A) r Evaluation (B) rb (C) rb+ (D) ab+ Q144 Suresh wants to open the binary file student.dat in read mode. He writes the following statement but he does not know the mode. Help him to find the same. F=open(‘student.dat’, ____) (A) r (B) rb (C) wb (D) w Application Q145 In which file type, no delimiters are used for line and no translations occur? (A) Text file (B) Binary file (C) CSV file (D) All of the above Knowledge Q146 The _________ files are used to store large data such as images, video files, audio files etc. (A) Text (B) Binary (C) CSV (D) None of the Above Analysis Q147 Which type of the file executes faster? (A) Text File (B) CSV File (C) Binary File (D) Word File Analysis C) import pickle D) All of the above Q161 Dump method is used to A) Write in a text file B) Write in a binary file C) Read from text file D) Read from binary file Knowledge Q162 Which module is needed to be imported to work with binary file? A) csv module B) random module C) binary module D) pickle module Analysis Q163 Which method is used to change the current file pointer position? A) offset() B) tell() C) seek() D) point() Knowledge Q164 In binary file data is stored in which format A) Binary B) Text C) ASCII D) UNICODE Understanding Q165 Binary file has advantage over text file. A) It occupies less memory B) It is fast to work with binary file C) Computer understands this data without any conversion D) All of the above Analysis Sl.No Question: Learning Objective Q166 The module, which can use to process binary file (A) json (B) lxml (C) pickle (D) none of these About basic library to use for binary file Q167 Correct statement to declare necessary library to process the records by directly access the audio data as python objects Knowledge about syntax to use pickle (A) pickle import (B) import pickle as pkd (C) import audio (D) audio import Q168 The method used to serialise the python objects for writing data in binary file (A) dump( ) (B) open( ) (C) write( ) (D) serialise( ) Awareness about method of pickle module to write data Q169 The statement to prepare the buffer in memory to examine the contents of the binary file (‘data.dat’) (A) f=open( “data.dat” , “r”) (B) f=open( data.dat , “rb” ). (C) f=open( data.dat, “r” ) (D) f=open( “data.dat” , “rb” ) The correct syntax of use of open( ) function to read binary file Q170 The method used to unpickling the data from a binary file (A) unpickle( ) (B) load( ) (C) deserialise( ) (D) read( ) Awareness about the method to load data from binary file to process Q171 What is wrong with the following code ? listvalues = [1, “Geetika”, ‘F’, 26] fileobject = open( ‘mybinary.dat’ , ‘wb’ ) fileobject.write ( listvalues) fileobject.close( ) (A) error in open mode of file (B) error, pickle is essential to use write( ) Awareness about that write( ) on binary file requires bytes only. (C) error in write( ) (D) No error Q172 Let the file ‘abc.csv’ contains the following records in comma separated way 1,Geetika,F,26 2,Jeevan,M,24 Consider the following code fileobject = open( ‘abc.csv’ , ‘rb’ ) contents=fileobject.read( ) lst=contents.split( ) for rec in lst: print(lst.split(‘,’)[1],end=’#’) fileobject.close( ) Find the output of above code (A) runtime error (B) syntax error (C) 1#2# (D) Geetika#Jeevan# Awareness about that, processing csv file using binary methods will not work without converting the loaded binary data to text format before further processing Q173 Through python code, a file ‘data.dat’ need to be created and store the following record [‘XIIA’,{‘no of students’:25, ‘average attendance’:26}] , which is to be stored in memory in form of python list as specified above. Consider the following code: import pickle fileobject=open( ‘data.dat’, ‘_____’ ) #statement1 listvalues =[‘XIIA’,{‘no of students’:25, ‘average attendance’:26}] Aware about correct opening mode to save the binary data into file Rima = {'name' : ‘Rima Sood‘ ,'age' : 43, 'pay' : 45000} db = {} db[' Robert'] = Robert db['Rima'] = Rima dbfile = open('data.dat', 'ab') pickle.dump(db, dbfile) dbfile.close() def loadData(): dbfile = open('examplePickle', 'rb') db = pickle.load(dbfile) p=0 for keys in db: p += db[keys][‘pay’] print(p) dbfile.close() storeData() loadData() (A) 45000 (B) 70000 (C) 25000 (D) none of these Q181. Which module is used to store data into python objects with their structure? (A)pickle (B) binary files (C) unpickle (D)None of these Understanding Q182 Which one of the following is the correct statement? (A)pickle import (B) import – pickle (C) import pickle (D)None of the above Understanding Q183 Which function is use for reading data from a binary file? (A) load() (B) read() (C) dump() (D)None of the above Application Q184 Which function is use for writing data in binary file? (A) load() (B) write() (C) dump() (D)None of the above Creation Q185 _______ the process in which an object converts into a byte stream (A)unpickling (B) pickling (C) (A) and (B) (D)None of the above Creation Q186 Serialization in binary file is also called __________ (A)Unpickling (B) Pickling (C) Both (A) and (B) (D)None of the above Creation Q187 ________ function places the file pointer at the specified position by in an open file. (A) tell() (B) seek() (C) both A and B (D)None of the above Knowledge Q188. _______ function return the current position of the file pointer. (A) tell() (B) seek() (C) both A and B (D)None of the above Knowledge Q189 Fill in the blank: import pickle f=open("data.dat",'rb') d=_____________________.load(f) # Statement1 f.close() (A)unpickle Understanding, Knowledge, Application, Evaluation (B) pickling (C) pickle (D)pick Q190 Which of the following function takes two arguments? a) load() b) dump() c) Both of the above d) None of the above Knowledge Q191 .pdf and .doc are examples of ________ files. (A)Text (B) Binary (C) CSV (D)None of the above Application Q192 The syntax of seek() is : file_object.seek(offset [,reference_point]). What all values can be given as a reference point? (A)1 (B) 2 (C) 0 (D)All of the above Understanding Q193 f.seek(10,0) will move 10 bytes forward from _______. (A) beginning (B) End (C) Current (D) None of the above Application Q194 Which statement will move file pointer 10 bytes backward from end position. (A)F.seek(-10,2) (B) F.seek(10,2) (C) F.seek(-10,1) (D)None of the above Understanding Q195 Aman opened the file “myfile.dat” by using the following syntax. His friend told him few advantages of the given syntax. Help him to identify the correct advantage. with open(“myfile.dat”, ‘ab+”) as fobj: (A)In case the user forgets to close the file explicitly the file will closed automatically (B) File handle will always be present in the beginning of the file even in append mode. (C) File will be processed faster (D)None of the above. Evaluation Q196 Which of the following method is used to clear the buffer? (A)clear() (B) buffer() Analysis d) None of the above Q207 Almost all the files in our computer stored as _______ file. a) Text b) Binary c) CSV d) None of the above Knowledge Q208 Read the code given below and answer the question: import pickle Fi=open("main.dat","wb") pickle.dump("bye",Fi) Fi.close() If the file main.txt contains Good before execution, what will be the content of the file after execution. a) Good Bye b) Bye c) Nothing d) Byed Analysis Q209 Which of the following is not true about binary files? a) Binary files are store in terms of bytes b) When you open binary file in text editor will show garbage values c) Binary files represent ASCII value of characters d) All of the above Understanding Q210 In order to read the content from the Binary file, we can open file in a) “rb” mode b) “rb+” mode c) “wb+” mode d) All of the above Understanding Q211 Which of the following method is used to clear the buffer? a) clear() b) buffer() c) close() d) flush() Knowledge Q212 Fill in the blank in the given code : import pickle f = open("data.dat", "rb") l = pickle._______(f) print(l) f.close() a) dump() b) load() c) write() d) read() Analysis Q213 Fill in the blank in the given code : import pickle f = open("data.dat", "wb") L = [1, 2, 3] pickle._______ f.close() a) dump(L,f) b) dump(f,L) c) load(L,f) d) load(f,L Analysis Q214 Which of the following module is provided by Python to do several operations on the CSV files? (A) os (B) xls (C) csv Understanding (D) py Q215 Which of the following is tasks cannot be done or difficult with CSV module? (A) Storing data in tabular form (B) Finding data uniquly (C) Saving data permanently (D) All of these Understanding Q216. The writer() function of csv module has how many mandatory parameters? (A) 4 (B) 3 (C) 2 (D) 1 Creation Q217 Which of these is not relevant to csv file? (A) Text file (B) Binary file (C) Easily openable in text editor (D) None of the above Understanding Q218 You are having myfile.csv file on c drive. You want to access it in python, how can you do this? (A) source=”c:\\myfile.csv” data = pd.read_csv(source) (B) source=”c:\\myfile.csv” data = pd.reads_csv(source) (C) source=”c:\\myfile.csv” data = pd.reader(source) (D) None of the above Application Q219 Which is the correct way to import a csv module? (A) import csv (B) from csv import * (C) None of the above (D) Both A & B Application Q220 In regards to separated value in files such as .csv and .tsv, what is the delimiter? (A) Any character such as the comma (,) or tab ;) used to separate the column data. (B) Delimiters are not used (C) Only the comma (,) character is used in the file (D) Any character such as the comma (,) or tab ;) used to separate the row data. Understanding Q221 In separated value files such as .csv, what does the first row in the file typically contain? (A) The author name (B) Notes about the data Understanding (B) .pdf (C) .csv (D) None of the above Q233 Which of the following Python statement is used to read the entire content of the CSV file as a nested list from a file object infile? (A) infile.read() (B) infile.reader() (C) csv.reader(infile) (D) infile.readlines() Understanding Q234 What is the full form of CSV? (A) Comma Separated Values (B) Comma Separated Value (C) Comma Separated Variables (D) Comma Separate Values Knowledge Q235 EOL character used in windows operating system in CSV files is (A) \r\n (B) \n (C) \r (D) \0 Knowledge Q236 _________ is the default delimiter character of a CSV file. (A) : (colon) (B) \t (tab) (C) , (comma) (D) ; (semi-colon) Knowledge Q237 A CSV file marks.csv is stored in the storage device. Identify the correct option out of the following options to open the file in read mode. i. myfile = open('marks.csv','r') ii. myfile = open('marks.csv','w') iii. myfile = open('marks.csv','rb') iv. myfile = open('marks.csv') (A) only i (B) both i and iv (C) both iii and iv (D) both i and iii Application Q238 Which of the following is a function of the csv module? (A) readline() (B) reader() (C) read() (D) readrow() Knowledge Q239 What is the output of the following program? import csv d=csv.reader(open('city.csv')) for row in d: print(row) break If the file called city.csv contains the following details Bhubaneshwar, Kolkata Guwahati, Silchar (A) Guwahati, Silchar (B) Bhubaneshwar, Kolkata (C) Bhubaneshwar, Kolkata Application Guwahati, Silchar (D) Bhubaneshwar Guwahati Q240 The CSV files are _______ files. (A) Python (B) Binary (C) Data (D) Text Knowledge Q241 The writer() function has how many mandatory parameters? (A) 1 (B) 2 (C) 3 (D) 4 Understanding Q242 Vikas wants to separate the values in a csv file by a # sign. Suggest to him a pair of function and parameter to use it. (A) open,quotechar (B) writer,quotechar (C) open,delimiter (D) writer, delimiter Understanding Q243 Which of the following option is correct? i. if we try to read a csv file that does not exist, an error occurs. ii. if we try to read a csv file that does not exist, the file gets created. iii. if we try to write on a csv file that does not exist, an error occurs. Understanding Q50 D Q51 A Q52 C Q53 B Q54 B Q55 C Q56 D Q57 D Q58 A Q59 C Q60 A Q61 D Q62 D Q63 C Q64 B Q65 D Q66 A Q67 A Q68 D Q69 A Q70 A Q71 A Q72 A Q73 A Q74 C Q75 A Q76 (b) fobj.read() Q77 (a) fp.seek(offset, 0) Q78 (b) fp.tell() Q79 (d) results in an error Q80 (a) readline() Q81 a. seek() Q82 a) sets the file‟s current position at the offset Q83 a) fp.seek(offset, 0) Q84 a. 0 Q85 a) fp.seek(offset, 0) Q86 d) error Q87 b. List Q88 b. read(n) Q89 a. File- Q90 c. FileHandling Q91 A Q92 C Q93 B Q94 A Q95 B Q96 D Q97 A Q98 D Q99 A Q100 A Q101 D Q102 D Q103 D Q104 B Q105 A Q106 D Q107 B Q108 C Q109 A Q110 B Q111 C Q112 A Q113 A Q114 B Q115 A Q116 D Q117 D Q118 B Q119 D Q120 B Q121 D Q122 D Q123 C Q124 A Q125 D Q126 D Q127 D Q128 C Q129 B Q130 B Q131 B Q132 D Q133 B Q134 B Q135 C Q136 (A) A stream of bytes Q137 (B) b Q138 (A) Pickling Q139 (D) Every line ends with new line character ‘\n’ Q140 (C) rb+ Q141 (D) B & C both Q142 (C) ab+ Q143 (A) r Q204 D Q205 A Q206 B Q207 B Q208 B Q209 C Q210 D Q211 D Q212 B Q213 A Q214 (C) csv Q215 (B) Finding data uniquly Q216 (D) 1 Q217 (B) Binary file Q218 (A) source=”c:\\myfile.csv” data = pd.read_csv(source) Q219 (D) Both A & B Q220 (A) Any character such as the comma (,) or tab ;) used to separate the column data Q221 (C) Column Heading Q222 (D) DataFrame Q223 (A) writerrow() Q224 (B) infile = open(“c:\\myscore.csv”, “r”) Q225 (D) All of the above Q226 (C) csv.reader(infile) Q227 (D) ab Q228 (D) All the above Q229 c) The column data as a list Q230 c) newline Q231 b) The column names of the data Q232 c) .csv Q233 c) csv.reader(infile) Q234 a) Comma Separated Values Q235 a) \r\n Q236 c) , (comma) Q237 b) both i and iv Q238 b) reader() Q239 b) Bhubaneshwar, Kolkata Q240 d) text Q241 a) 1 Q242 d) writer, delimiter Q243 d) both I and iv Name of the vetter- KAMAL KANT GUPTA Name of the KV- KV 2 KANCHRAPARA Region- KOLKATA Mobile No- 9493887480 E-mail ID -
[email protected] Name of the Chapter- DATA FILE HANDLING Question No Question Content Learning Objective(if Provided) Q1. Assertion: It is not necessary to always create the file in the same default folder where Python has been installed. Reason: In binary file, there is no delimiter for a line. (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Knowledge Q2. Assertion: The relative paths are relative to current working directory. Reason: The relative path for a file always remains same even after changing the directory. (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Knowledge Q3. Assertion: When you open a file for writing, if the file does not exist, an error occurs. Reason: When you open a file for writing, if the file exists, the existing file is overwritten with the new file. (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Understanding Q4. Assertion: The offset argument to seek() method indicates the number of bytes to be moved. Reason: If the offset value is set to 2, beginning of the file would be taken as seek position (A) Both Assertion and reason are true and reason is correct explanation of assertion. Understanding Q12. Assertion: It's mandatory to mention file mode while opening a file for reading. Reason: By default, the file opens in read mode. (A) Both Assertion and reason are true and reason is the correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. KNOWLEDGE AND UNDERSTANDING Q13. Assertion: File can be opened using open() function and “with open() as f:” syntax. Reason: Once a file is opened it can’t be closed. (A) Both Assertion and reason are true and reason is the correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. KNOWLEDGE AND UNDERSTANDING Q14. Assertion: There is no need to close a file explicitly if opened using “with open() as f:” syntax. (where f is file stream object) Reason: file gets closed using syntax f.close() where f is a file stream object. (A) Both Assertion and reason are true and reason is the correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. APPLICATION Q15. Assertion: With the code given below a user can write multiple lines one by one into a text file ‘readme.txt’ lines = ['This is line 1', 'This is line 2'] with open('readme.txt', 'w') as f: for line in lines: f.write(line+’\n’) Reason: As there is no error in code and as the write() method only writes a single line at a time by appending ‘\n’ to each string of list lines. (A) Both Assertion and reason are true and reason is the correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. ANALYSIS, EVALUATION AND CREATION Q16. Assertion: Text File in Python by default open in reading mode. Reason: When open a file in reading mode, file must be exits. (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Creation Q17. Assertion: Every File maintains a file pointer which tells the current position in the file where writing or reading will takes place. Reason: file pointer advances by the specified number of bytes. (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Creation Q18. Assertion: The function readline( ) reads a line at a time. Reason: The readline( ) function can be used to read the entire file. (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. Analysis (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Q19. Assertion: User can open a file into read and write mode at the same time.. Reason: Python provides function “r+” and “w+’ to open a file in read and write mode at the same time. (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Creaton Q20. Assertion: New content can be added to the existing file. Reason: The mode “a” is used for append mode. (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Understanding Q21. def count H (): f = open (“para.txt” , “r” ) lines =0 l=f. readlines () for i in L: if i [0]== ‘H’: lines +=1 print (“No. of lines are: “ , lines) UNDERSTANDING KNOWLEDGE ANALYSIS EVALUATION (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Q26. Assertion: readline() function will read one line from the file. Reason: readlines() function will read all the lines from the files. (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Knowledge Understanding Analysis Q27. Assertion: To read twelve characters from a file object fin we use fin.read(). Reason: We can use readline( ) function which can read one line at a time from the file. (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Knowledge Understanding Analysis Q28. Assertion: >>> myobj=open("myfile.txt", 'r') >>> print(myobj.readlines()) This code will read all the lines from the file. Knowledge Understanding Analysis Reason: readlines() function reads all the lines from a text file. (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Q29. Assertion: In code given below, the file object will move 10 bytes file_object.seek(10, 0) Reason: Seek() function with negative offset only works when file is opened in binary mode. (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Knowledge Understanding Analysis Q30. Assertion: Ravi opened the file myfile.txt in append mode. In this file the file object/file handle will be at the end of the file. Reason: ‘w’ (mode write) mode is default file mode. (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Knowledge Understanding Analysis Q31 Assertion: Text files stores information in ASCII and Unicode characters Reason: In text files there is no delimiter for a line (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. Knowledge & understanding (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Q32 Assertion: A file created using the statement: r = open( “text” ) is a text file Reason: Since the name of the file in open( ) is ‘text’ so the statement creates a text file (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Knowledge & understanding Q33 Assertion: f=open(‘abc.txt’,’r’) L=len(f.read()) Print(f.read()) the above code will return No output Reason: first read() statement put the file pointer at the end of file, so next f.read() will Return nothing (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Understanding & application Q34 Assertion: myfile = open("Myfile.txt") data_rec = myfile.readlines() myfile.close() in the above code, data type of data_rec is a list class. Reason: Myfile.txt is a text file so it contains only list of text lines. (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Knowledge & understanding Q35 Assertion: f=open(‘story.txt’,’r+’) Above statement will create a new file, it it is not exist. Knowledge and understanding (A) Both Assertion and reason are true and reason is the correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Q43. Assertion: While opening a binary file in append mode ‘ab’ , if the file exists ,the data in the file is retained and the new data is written at the end of the file. Reason: If the file does not exist ,Python will create a new file in ‘ab ‘ mode. (A) Both Assertion and reason are true and reason is the correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Analysis Q44. Assertion: While opening a binary file in read only mode ‘rb+’ , the file must exist. Reason: Python raises I/O error if the file is unavailable while opening file in ‘rb+’ mode. (A) Both Assertion and reason are true and reason is the correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Analysis Q45. Assertion: While opening a binary file in write and read mode ‘wb+’ , if the file doesn’t exist ,file is created. Analysis Reason: If the file exists,Python python will overwrite the current file in ‘wb+’ mode. (A) Both Assertion and reason are true and reason is the correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Q46. Assertion: There is no line delimeter in binary files. Reason: Binary file stores data line by line. (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Knowledge Q47. Assertion: open() method uses the ‘path & filename’ with ‘mode of opening’ a binary file. Reason: There are three modes to open a file in python that are read, write and append. (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Understanding Q48. Assertion: Access mode ‘ab’ opens a file for appending data. Reason: The file pointer is at the end of the file in the file exists. (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Application Q49. Assertion: Binary file stores data in a format understand easily by the computer hardware. Reason: Computer hardware only understand the binary language. (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Analysis Q50. Assertion: ‘rb+’ mode opens a binary file in read only mode. Reason: The file pointer in ‘rb+’ mode exist at the beginning of file. (A) Both Assertion and reason are true and reason is correct explanation of assertion. Evaluation Q59 Assertion: “L=[3,4] ; f=open(‘L1.dat’,’wb’); pickle.dump(L,f); f.close( ) “ => Serialise the [3,4] as byte squence into file L1.dat Reason: pickle.dum( A , B) => Serialise the Python object A as a byte stream onto the file using fileobject B (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Serialisation Process Q60 Assertion: d={‘a’:12, ‘b’:10}; f=open(‘data.dat’, ‘wb’); f.write( d ); f.close( ) => Python object d is serialised onto file using file object f Reason: d={‘a’:12, ‘b’:10}; f=open(‘data.dat’, ‘wb’); pickle.dump( d, f); f.close( ) => Python object d is serialised onto file using file object f (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Difference between Writing memory block and Serialisation of object Q61 Assertion: CSV is a kind of plain text file Reason: It can be opened in all type of programs (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Understanding Q62 Assertion: First use open() method to read data from file Reason: File File object is required to read data with the help of csv.reader object/method (A) Both Assertion and reason are true and reason is correct explanation of assertion. Creation (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Q63 Assertion: We should use with() statement to write csv related statement Reason: with() statement at end releases all the resources automatically without using close() (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Application Q64 Assertion:CSV is best suitable to open in text editor Reason: Most of the files can be opened in text editor (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Understanding Q65 Assertion:close() method must be called as last statement related to csv file object Reason: As it releases the assigned resources (A) Both Assertion and reason are true and reason is correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Evaluation Q66.. Assertion: While writing data to csv file, we set the value of parameter newline to "" in the open() function to prevent blank rows. Reason: EOL translation is suppressed by using newline="". (A) Both Assertion and reason are true and reason is the correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. Application (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Q67. Assertion: The CSV module in Python’s standard library presents methods to perform read/write operations on CSV files. Reasoning: To write data to a CSV file, we can use built-in function writer(). (A) Both Assertion and reason are true and reason is the correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Knowledge Q68. Assertion: To open a CSV file employee.csv in write mode, we can give python statement as follows: fh=open('employee.csv’) Reasoning: If we try to write on a csv file that does not exist, the file gets Created (A) Both Assertion and reason are true and reason is the correct explanation of assertion. (B) Assertion and reason both are true but reason is not the correct explanation of assertion. (C) Assertion is true, reason is false. (D) Assertion is false, reason is true. Understanding Q69. Assertion: We can open a CSV file in the same way as a text file for reading and writing data. Reason: A CSV file is a text file that uses a delimiter to separate values. Understanding Q36 C Q37 B Q38 A Q39. B Q40. D Q41. A Q42. B Q43. B Q44. A Q45. B Q46. (C) Assertion is true, reason is false Q47. (B) Assertion and reason both are true but reason is not the correct explanation of assertion Q48. (A) Both Assertion and reason are true and reason is correct explanation of assertion. Q49. (A) Both Assertion and reason are true and reason is correct explanation of assertion. Q50. (D) Assertion is false, reason is true. Q51 D Q52 C Q53 B Q54 D Q55 D Q56 A Q57 D Q58 C Q59 A Q60 D Q61 B Q62 A Q63 A Q64 C Q65 A Q66.. a) Both Assertion and reason are true and reason is the correct explanation of assertion. Q67. c) Assertion is true, reason is false. Q68. d) Assertion is false, reason is true. Q69. a) Both Assertion and reason are true and reason is the correct explanation of assertion. Q70. c) Assertion is true, reason is false. Name of the vetter- Kamal Kant Gupta Name of the KV- No 2 Kanchrapara Region- Kolkata Mobile No-9493887480 E-mail ID -
[email protected] Name of the Chapter- DATA FILE HANDLING CBQ NO Question Content Learning Objective(if Provided) Q1. Ramesh is learning Python in preparation for an internship exam. He is having a problem with one question in which she has been assigned an incomplete Python code (given below) to create a CSV file called ‘Employee.csv.’ Assist her in completing the code that generates the CSV file with the given content. Incomplete Code: ______ #Statement 1 Csvfile = open(______, _______, newline=’’) #Statement 2 CsvObj = csv. ________( ________) #Statement 3 Rows = [] Fields = [‘Empnumber’, ‘EmpName’, ‘EmpDesig’, ‘EmpSalary’] Rows.append(Fields) for i in range(5): Empno = input(“Enter Employee No:”) Name = input(“Enter Employee Name:”) Desig = input(“Enter Designation:”) Salary = int(input(“Enter Salary:”)) records= [________________] #Statement 4 Rows.________(______) #Statement 5 _______._______(Rows) #Statement 6 Csvfile.close() a. Identify the relevant module to import in the blank space in line marked as Statement 1. (A) import pickle (B) import txt (C) import csv file (D) import csv Application c. Identify the suitable code for blank space in the line marked as Statement 3. (A) load(records,file) (B) dumps(record,file) (C) dump(records,file) (C) load(file,records) d. Identify the suitable code for blank space in line marked as Statement 4. (A) pickle.load(F) (B) pickle.dump(f) (C) pickle.load(R) (D) pickle.load(f) e. Identify the suitable code to calculate the total Amount in the line marked as Statement 5. (A) total_Amt=R[4] (B) total_Amt=R[3]+R[4] (C) total_Amt+=R[4] (D) total_Amt=R[4]*2 f. Identify the suitable keyword to handle the exception (if any) that occurs during execution of the try clause. (A) catch (B) except (C) stop (D) exception Q3. A programmer has confusion in understanding the behavior of opening a file in "w" mode. Clear his/her confusion, by suggesting the correct option among the given below. The behavior of "w" mode is A. Opening fails if the file exists already. B. Opening fails if the file does not exist already. C. Opening will be succeeded if file exists with data and keeps the data intact. D. Opening will be succeeded, if the file exists replaces the contents, if do not exist, creates a new file. Q4. Rehang is assigned the task to storing the information of his class mates as student records in a text file “Stu2021.txt”. He wants to create a file to write the records. Which of the following is not a valid mode to open a file for writing the data? A. w B. r+ C. r D. w+ 1. Abhinav is a student of class XII, he wants to create a file through python program which can open in excel also, what type of file you will suggest to create. A. Binary B. CSV C. Both D. None 1. Mrs. Bhatia is running her own boutique business. She wants to store data of all orders permanently and fast processing of data through her boutique software. Suggest her to choose the appropriate technique among the following. A. She can use Python Dictionaries with Binary file concept. B. She can use Python Dictionaries with Text files. C. She can use Python Lists without the Binary files concept. D. She can use Python Dictionaries without the Binary file concept. 1. Rohit, a class 12th student, wants to write a program to read a binary file, Which python module needs to be imported by Rohit in his program. A. binary B. pickle C. data D. file Q5 Ramesh wants to write into an existing file ‘story.txt’ which already had some important content in it. He has APPLICATION, written the code given below. Help him to complete this code. fout = open('story.txt',_________) # STATEMENT 1 print("Name of the file:", fout.name) n = int(input("No. of lines to be entered:")) l = [] for i in range(n): fil_str = input("Enter string:") fil_str = _________________ # STATEMENT 2 l.append(fil_str) fout._______________ # STATEMENT 3 __________________ # STATEMENT 4 ANALYSIS, EVALUATION AND CREATION i) Complete the code for statement 1 by writing access mode to open the file for writing. (Consider file already exists with some important data) (A) a (B) r (C) w (D) b KNOWLEDGE AND UNDERSTANDING ii) Complete the code for statement 2 by adding a newline character to the string entered by the user. (A) ‘\n’ (B) fil_str+newline (C) fil_str+’\n’ (D) fil_str+’\N’ APPLICATION iii) Complete the code for statement 3 by replacing the spaces with the code for writing multiple strings/lines at once in the file. (A) writeline() (B) writelines(l) (C) writelines() (D) writestrings() APPLICATION iv) Replace the code for statement 4 by closing the file. (A) f.close() (B) close() (C) close(f) (D) fout.close() KNOWLEDGE AND UNDERSTANDING Q6 Deepti wants to write into an existing file ‘story.txt’ which already has some important content in it. She has written the code given below. Help her to complete this code and analyze the output. fout = ________________________ # STATEMENT 1 APPLICATION, ANALYSIS, EVALUATION AND CREATION Q9 During the practical examination of Computer Science, Amit has been assigned an incomplete search() function to search in a text file “EMP.txt”. The file “EMP.txt” is created by his Teacher and the following information is known about the file: • File contains details of employees in text format • File contains details of employees like Worker, Supervisor, Manager Amit has been assigned the task to complete the code and print the number of the word Manager. def search(): f = open("EMP.txt",) #Statement-1 A=____________________ #Statement-2 ct=0 for x in A: p=x.split() if p==”Manager”: ct+=1 print(ct) close() #___________________ #Statement-3 i. Name the function that can be used by Amit to read the content of the file in statement-2. a) f.read( ) b) f.readline () c) f.readlines( ) d)f.readl() UNDERSTANDING KNOWLEDGE ANALYSIS EVALUATION ii.Name the mode that can be used by Amit to read the content of the file in statement-1. a) w b) r c) readlines d)readl() iii Complete the function that can be used by Amit to close the the file in statement-3. a) f.read( ) b) f.close () c) f.readlines( ) d) f.closed () Q10 Sunaina wants to write a method in python to read lines from a text file MYNOTES.TXT and display those lines which start with alphabets 'K'-- def display (): file=open(MYNOTES.TXT’ , ____) # statement-1 lines=file._________() # statement-2 while line: if line[0]==’K’ : print(line) line=file.______() # statement-3 file.close() i.Name the mode that can be used by Amit to read the content of the file in statement-1. a) w b) r UNDERSTANDING KNOWLEDGE ANALYSIS EVALUATION c) readlines d)readl() ii Name the function that can be used by Sunaina to read the content of the file in statement-2. a) f.read( ) b) f.readline () c) f.readlines( ) d)f.readl() iii Name the function that can be used by Sunaina to read the content of the file in statement-3. a) f.read( ) b) f.readline () c) f.readlines( ) d)f.readl() Q11 (CASE STUDY: 1) f=open("data.txt",'w') f.write("Hello") f.write("Welcome to my Blog") f.close() f=open("data.txt",'r') d=f.read(5) print(d) # First Print Statement f.seek(10) d=f.read(3) print(d) # Second Print Statement f.seek(13) d=f.read(5) print(d) # Third Print Statement d=f.tell() print(d) # Fourth Print Statement Knowledge Understanding Analysis Application