Q. Write a Python program to modify the price of an item in the binary file Items.dat created data. Get the itemno of the item to be modified from the user.
Answer :-
import pickle file = open("items.dat","rb") data = [] try : while True : data.append( pickle.load( file ) ) except : file.close() itemno = int(input("Enter item Number (for correction of price):- ")) for i in range( len( data )) : if data [i] [0] == itemno : price = float(input ("Enter New Price :- ")) data [i][2] = price print("New price added successfully !!") file = open("items.dat","wb") for i in data : pickle.dump( i , file ) file.close()
Output :-
Enter item Number (for correction of price):- 4896
Enter New Price :- 796.58
New price added successfully !!
>>>
Enter New Price :- 796.58
New price added successfully !!
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )