Q. Write a program to append some records to the binary file Items.dat, created in the previous program.


Answer :-

import pickle
file = open("items.dat","ab")
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 added successfully !!")
file.close()

Output :-

Enter item Number (for quit enter -1 ):- 4896
Enter Name of item :- Computer Portal
Enter price of item :-789.63
Enter Category of item :- YouTube

Enter item Number (for quit enter -1 ):- 75698
Enter Name of item :- Python
Enter price of item :-1478.25
Enter Category of item :- Programing Language

Enter item Number (for quit enter -1 ):- -1

File added successfully !!

>>>

Post a Comment

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

Previous Post Next Post