CBSERanker

Loading

Worksheet 24091102 Binary file

Worksheet 24091102 Binary file

MCQs :

  1. Which mode is used to open a binary file for both reading and writing?
    • (A) rb+
    • (B) wb+
    • (C) ab+
    • (D) rb
  2. Which module needs to be imported in Python for binary file operations?
    • (A) json
    • (B) pickle
    • (C) os
    • (D) file
  3. What does the wb mode do in binary file operations?
    • (A) Opens a binary file for reading
    • (B) Opens a binary file for writing (overwriting the file if it exists)
    • (C) Appends to a binary file
    • (D) Opens a binary file for both reading and writing
  4. Which method is used to write data to a binary file using the pickle module?
    • (A) load()
    • (B) write()
    • (C) append()
    • (D) dump()
  5. What is the function of rb mode in binary file operations?
    • (A) Read and write
    • (B) Read only
    • (C) Write only
    • (D) Append only
  6. Which method is used to load or read data from a binary file using the pickle module?
    • (A) write()
    • (B) dump()
    • (C) load()
    • (D) read()
  7. To append data to an existing binary file, which mode should you use?
    • (A) rb
    • (B) wb
    • (C) ab
    • (D) rb+
  8. Which of the following operations is not directly supported by the pickle module?
    • (A) Writing data to a binary file
    • (B) Loading data from a binary file
    • (C) Searching data in a binary file
    • (D) Appending data to a binary file

Assertion-Reasoning:

  1. Assertion (A): The wb+ mode in binary file operations allows both reading and writing.
    Reason (R): The wb+ mode opens the binary file for writing only, and overwrites the file if it exists.
    • (A) Both A and R are true, and R is the correct explanation of A.
    • (B) Both A and R are true, but R is not the correct explanation of A.
    • (C) A is true, but R is false.
    • (D) A is false, but R is true.
  2. Assertion (A): The dump() method is used to store Python objects in a binary file using the pickle module.
    Reason (R): The dump() method can append data to an existing binary file without overwriting.
    • (A) Both A and R are true, and R is the correct explanation of A.
    • (B) Both A and R are true, but R is not the correct explanation of A.
    • (C) A is true, but R is false.
    • (D) A is false, but R is true.

SQL Programming Questions:

  1. Write a Python program to open a binary file in write mode and store a list of numbers using the pickle.dump() method.
  2. Write a Python program to open an existing binary file in read mode and display the content using pickle.load().
  3. Write a Python program to append a new list of numbers to an existing binary file using ab mode.
  4. Write a Python program to search for a specific number in a binary file after loading its content.
  5. Write a Python program to create a binary file using wb mode and store a dictionary of student details.
  6. Write a Python program to update an existing binary file by reading, modifying a value, and writing it back using rb+ mode.
  7. Write a Python program to close a binary file after performing write operations and ensure no data is lost.
  8. Write a Python program to demonstrate reading from a binary file using rb mode and checking for EOF (End of File).
  9. Write a Python program to handle exceptions while performing dump() and load() operations on a binary file.
  10. Write a Python program to open a binary file in ab+ mode and append a set of records, then read and display all the records.

Leave a Reply

Your email address will not be published. Required fields are marked *