CBSERanker

Loading

worksheet 24091201 CSV file

worksheet 24091201 CSV file

MCQs :

  1. Which Python module is used for working with CSV files?
    • (A) os
    • (B) csv
    • (C) json
    • (D) pickle
  2. Which method is used to write a row of data into a CSV file in Python?
    • (A) write()
    • (B) writerow()
    • (C) writer()
    • (D) reader()
  3. Which mode is used to open a CSV file for writing?
    • (A) r
    • (B) rb
    • (C) w
    • (D) a
  4. What does the writerows() method do in Python’s CSV module?
    • (A) Writes a single row of data
    • (B) Writes multiple rows of data
    • (C) Reads multiple rows of data
    • (D) Appends rows to a file
  5. How can you read from a CSV file in Python?
    • (A) csv.writer()
    • (B) csv.reader()
    • (C) csv.writerow()
    • (D) csv.read()
  6. Which file mode should be used to append data to an existing CSV file?
    • (A) r
    • (B) w
    • (C) a
    • (D) x
  7. What does the close() method do after writing into or reading from a CSV file?
    • (A) Saves changes and closes the file
    • (B) Reopens the file for reading
    • (C) Appends new data
    • (D) Deletes the file
  8. Which of the following is true about CSV files?
    • (A) CSV files store data in binary format
    • (B) CSV files store data in a structured, tabular format
    • (C) CSV files are limited to numerical data
    • (D) CSV files can only be read in Excel

Assertion-Reasoning :

  1. Assertion (A): The writerow() method can be used to write a single row of data into a CSV file.
    Reason (R): The writerow() method can only write strings into a CSV file.
    • (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 reader() method in Python is used to read data from a CSV file.
    Reason (R): The reader() method returns each row of the file as a string.
    • (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.

Programming Questions:

  1. Write a Python program to open a CSV file and write a list of names into it using the writerow() method.
  2. Write a Python program to open a CSV file and append new data using the writerows() method.
  3. Write a Python program to read all the rows from a CSV file using the csv.reader() method.
  4. Write a Python program to read and display the content of a CSV file row by row.
  5. Write a Python program to create a CSV file and store student information (name, age, grade) using the writer() and writerow() methods.
  6. Write a Python program to read data from a CSV file and count the number of rows.
  7. Write a Python program to search for a specific value in a CSV file and display the corresponding row.
  8. Write a Python program to update data in a CSV file by reading the content, modifying a row, and writing it back.
  9. Write a Python program to handle exceptions while reading and writing to a CSV file using the csv module.
  10. Write a Python program to create a CSV file, write multiple rows of data, and close the file properly to ensure data integrity.

Leave a Reply

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