CBSE Class 12 Computer Science
Question 112 of 136
Data File Handling — Question 51
Back to all questionsimport csv
with open("Groceries.csv", mode = 'w', newline = '') as file:
writer = csv.writer(file)
while True:
item_code = int(input("Enter Item Code: "))
name = input("Enter Name of the Item: ")
price = float(input("Enter Price: "))
quantity = int(input("Enter Quantity: "))
writer.writerow([item_code, name, price, quantity])
choice = input("Wish to enter more records (Y/N)?: ")
if choice.upper() == 'N':
breakThe file "Groceries.csv" includes following records:
101,Soaps,45.5,5
102,Atta,34.0,2
103,Maggie,70.0,1