Q. Write a Python program to create a binary file Items.dat to store Item details of some items as per {itemno, name, price, category}.


Answer :-

import pickle
file = open("items.dat","wb")
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 ]
      pickle.dump( lst , file )
      print()
print()
print("File 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

File created successfully !!

>>>

Post a Comment

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

Previous Post Next Post