Test Index
CBSE Class 12 Computer Science 2023 Paper Compartment
© examsnet.com
Question : 35 of 35
Marks:
+1,
-0
Atharva is a programmer, who has recently been given a task to write a Python code to perform the following binary file operation with the help of a user defined function/module :• Copy_new() : to create a binary file
new_items.dat and write all the item details stored in the binary file, items.dat, except for the item whose item_id is 101. The data is stored in the following format :{item_id:[item_name,amount]}import ___________ # Statement 1def Copy_new(): f1=_____________ # Statement 2 f2=_____________ # Statement 3 item_id=int(input("Enter the item id")) item_detail=___________ # Statement 4 for key in item_detail: if _______________: # Statement 5 pickle.___________ # Statement 6 f1.close() f2.close()He has succeeded in writing partial code and has missed out certain statements. Therefore, as a Python expert, help him to complete the code based on the given requirements :(i) Which module should be imported in the program ? (Statement 1) (1)(ii) Write the correct statement required to open the binary file "items.dat". (Statement 2) (1)(iii) Which statement should Atharva fill in Statement 3 to open the binary file "new_items.dat" and in Statement 4 to read all the details from the binary file "items.dat". (2)OR (Option for part iii only)(iii) What should Atharva write in Statement 5 to apply the given condition and in Statement 6 to write data in the binary file "new_items.dat". (2)
Go to Question: