I have a single .txt file (update.txt) that has records of update changes I've made to my program. The contents are as follows:
make Apples 4
make Oranges 3
outstanding Bananas 1
restock Strawberries 40
restock Pineapples 23
How do I print out appropriately according to an option I choose (e.g. I just want to print out all the "restock" data). The output should be as such:
0-restock, 1-make, 2-outstanding. Enter choice: 0
Summarised Data for RESTOCK ***
Strawberries 40
Pineapples 23
Is the below code the correct way to do it?
choice = int(input("0-restock, 1-make, 2-outstanding. Enter choice: "))
if choice == 0:
print("Summarised Data for RESTOCK ***")
with open("update.txt") as openfile:
for line in openfile:
for part in line.split():
if "restock" in part:
print(f"{fruitType} {quantity}")