Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- stock = {}
- total_sold = 0
- while True:
- command = input()
- if command == "Complete":
- break
- parts = command.split()
- action, quantity, food = parts[0], int(parts[1]), parts[2]
- if action == "Receive" and quantity > 0:
- if food in stock:
- stock[food] += quantity
- else:
- stock[food] = quantity
- elif action == "Sell":
- if food not in stock:
- print(f"You do not have any {food}.")
- else:
- if stock[food] < quantity:
- print(f"There aren't enough {food}. You sold the last {stock[food]} of them.")
- total_sold += stock[food]
- del stock[food]
- else:
- stock[food] -= quantity
- total_sold += quantity
- print(f"You sold {quantity} {food}.")
- if stock[food] == 0:
- del stock[food]
- for food, quantity in stock.items():
- print(f"{food}: {quantity}")
- print(f"All sold: {total_sold} goods")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement