Important QnA binary files CS Class 12

Important QnA binary files CS Class 12 provides you QnA for the topic data file handling – Binary files operations for the Computer Science subject class 12.

Important QnA binary files CS Class 12

We are going to start this article Important QnA binary files CS Class 12 with objective type questions. So let’s start with fill in the blanks.

Fill in the blanks

[1] The _________ files are used to store large data such as images, video files, audio files etc.

–> Binary

[2] The process of converting the structure to a byte stream before writing to the file is known as _________.

–> Pickling

[3] The process of converting byte stream back to the original structure is known as _______.

–> Unpickling

[4]A ______ module is used to store data into an python objects with their structure.

–> pickle

[5]A _______ function of pickle module is used to write data into binary as well as a ____________ function of pickle module is used to read data from binary file.

–> dump(), load()

[6]The _____ file mode is used to handle binary file for reading.

–> rb

[7] The _____ file mode is used when user want to write data into binary file.

–> wb

[8] A ab file mode is used to _______ in binary file format.

–> appending

The next section of Important QnA binary files CS Class 12 will provides MCQ type questions.

MCQs

[1] 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’

[2] 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

[3] Which of the following file mode opens a file for reading and writing both as well as overwrite the existing file if the file exists otherwise creates a new file?

a) w

b) wb+

c) wb

d) rwb

[4] 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+

[5] Ms. Suman is working on a binary file and wants to write data from a list to a binary file. Consider list object as l1, binary file suman_list.dat, and file object as f. Which of the following can be the correct statement for her?

a) f = open(‘sum_list’,’wb’); pickle.dump(l1,f)

b) f = open(‘sum_list’,’rb’); l1=pickle.dump(f)

c) f = open(‘sum_list’,’wb’); pickle.load(l1,f)

d) f = open(‘sum_list’,’rb’); l1=pickle.load(f)

[6] Which option will be correct for reading file for suman from q-5?

–> Option ) f = open(‘sum_list’,’rb’); l1=pickle.load(f)

[7] In which of the file mode existing data will be intact in binary file?

a) ab

b) a

c) w

d) wb

[8]Which one of the following is correct statement?

a) import – pickle

b) pickle import

c) import pickle

d) All of the above

In the next section of Important QnA binary files CS Class 12, we will discuss short answer questions.

Short Answer Questions – binary files in python class-12

Read the file handling class 12 python – notes for binary files which is Recommended article for answer of the following questions.

[1] Write steps to append data into binary files.

[2] Mention steps to search a record from binary files.

[3] Elaborate steps to update records in binary file.

[4] Write steps to delete records from binary file.

[5] Compare how binary files are better than text files?

[6] Explain various file modes can be used with binary file operations.

[7] What is pickle module? How to import pickle module in python program?

[8] How to use dump() and load() functions?

The next section of Important QnA binary files CS Class 12 contains the case study based questions.

Case study Based questions

[1] Ms. Sejal is working on the sports.dat file but she is confused about how to read data from the binary file. Suggest a suitable line for her to fulfill her wish.

import pickle
def sports_read():
    f1 = open("sports.dat","rb")
    _________________
    print(data)
    f1.close()    
sports_read()

–> data = f1.load(f)

[3] Improve above code and write the correct code to display all records from the file.

f1 = open("sports.dat","rb")
    try:
        while True:
            dt = pickle.load(f1)
            print(dt)
    except Exception:
      f1.close()

[2] Develop python code to insert records in g_meet.dat binary file until user press ‘n’. The information is Google meeting id, google meeting time, and class.

f1 = open("g_meet.dat","ab") 
    while True:
        gmeet_id=input("Enter id:")
        gmeet_time=input("Enter time:")
        gmeet_class =int(input("Enter google meet class:"))
        rec={"Google Meeting id":gmeet_id,"Gogole Meet Time":gmeet_time,"Google Meet Class":gmeet_class}
        pickle.dump(rec,f1)
        ch = input("Want more records:")
        ch=ch.lower()
        if ch=='n':
            break
    f1.close()

[3] Write a function to update record from g_meet.dat file.

[4] Create a function to delete a record from g_meet.dat file.

I hope you enjoyed the article Important QnA binary files CS Class 12.

Thank you for reading this article Important QnA binary files CS Class 12. Ask your doubts for binary file handling in python class 12, share this article with your friends using the share button.

Leave a Reply