'''GRADE 12 - PRACTICAL 13 - BINARY FILES
A binary file "Inventory.dat" stores product records
where each record is as below:
{"pname": <str>, "categ": <str>, "price": <float>}
i) WAF Create() to input multiple products and add
them into the file.
ii) WAF Display() to display all records and the average
price of the products.
iii) WAF Search() for a certain pname and display its
category if found.
iv) WAF Update() to increase the cost of all items in the
'food' category by 5 percent.'''
def Create():
with open("Inventory.dat", "ab") as f:
n = int(input("Enter no of records : "))
for i in range(n):
pname = input("Enter Product Name: ")
categ = (input("Enter Category: ").lower())
price = float(input("Enter Price: "))
record = {"pname": pname, "categ": categ, "price": price}
pickle.dump(record, f)
def Display():
pass
def Search():
pass
def Update():
pass
while True:
print("""\nMENU
1. Add Records
2. Display
3. Search
4. Update
5. Exit""")
choice = input("Enter your choice (1-5): ")
if choice == "1":
Create()
elif choice == "2":
Display()
elif choice == "3":
Search()
elif choice == "4":
Update()
elif choice == "5":
print("Exiting program. Goodbye!")
break
else:
print("Invalid Choice!")