Python file
Python file
5 Write a Python program to display all the records in a file along with
line/record numbers.
7 A binary file "Book.dat" has a structure [Book No, Book Name, Author,
Price]. Write a user-defined function Createfile() to input data for a
record and add it to 'Book.dat'. Also, write a function Countrec(Author)
in Python which accepts the Author name as a parameter and counts
and returns the number of books by the given Author stored in the
binary file "Book.dat".
16 What are the benefits of using the "with open()" method over "open()"
while opening a file? Write a Python program that defines and calls the
following user-defined functions: i) Add_item to accept and add data
of stationary items to a CSV file "stationery.csv". The record consists of
a list with field elements as Item_Id, Item_name, and Item_price. ii)
Count() to count the total number of stationary items in the CSV file.