Q. Create a CSV file "Groceries" to store information of different items existing in a shop. The information is to be stored w.r.t. each item code, name, price, qty. Write a program to accept the data from user and store it permanently in CSV file.
Answer =
import csv
data = []
while True :
item_code = input("Enter item code :-")
name = input("Enter name :-")
price = input("Enter price :-")
qty = input("Enter Quantity :-")
data += [[ item_code, name, price, qty ]]
user = input("Do you want to enter more data (yes/no)")
if user == "No" or user == "no" :
break
with open("Groceries.csv","w",newline="") as f :
csv_w = csv.writer(f,delimiter=',')
csv_w.writerows(data)
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )