Q. Write a Python program to get 10 items' details (itemno, name, price, category) from the user and create a CSV file (Items.csv).


Answer :-

import csv
file = open("items.csv","w")
itemwriter = csv.writer( file )
while True :
      itemno = int(input("Enter item Number (for quit enter -1 ):- "))
      if itemno == -1 :
            break
      name = input("Enter Name of item :- ")
      pri = float(input ("Enter price of item :-"))
      cat = input("Enter Category of item :- ")
      lst = [ itemno, name,  pri, cat ]
      itemwriter.writerow( lst )
      print()
print("Created Successfully !!")
file.close()

Output :-


Enter item Number (for quit enter -1 ):- 6544
Enter Name of item :- Path Walla
Enter price of item :-565.985
Enter Category of item :- Website

Enter item Number (for quit enter -1 ):- 6541
Enter Name of item :- Portal Express
Enter price of item :-564
Enter Category of item :- youtube

Enter item Number (for quit enter -1 ):- -1
Created Successfully !!
>>>

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post