Advertisement
bl00dt3ars

Untitled

Aug 20th, 2021 (edited)
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. information = {}
  2. command = input()
  3. sold_quantity = 0
  4.  
  5. while not command == 'Complete':
  6.     command, quantity, food = command.split()
  7.     if command == 'Receive':
  8.         if food not in information and int(quantity) > 0:
  9.             information[food] = int(quantity)
  10.         elif int(quantity) > 0:
  11.             information[food] += int(quantity)
  12.     elif command == 'Sell':
  13.         if food not in information:
  14.             print(f'You do not have any {food}.')
  15.         elif information[food] < int(quantity):
  16.             sold_quantity += information[food]
  17.             print(f"There aren't enough {food}. You sold the last {information[food]} of them.")
  18.             information.pop(food)
  19.         else:
  20.             sold_quantity += int(quantity)
  21.             information[food] -= int(quantity)
  22.             print(f'You sold {quantity} {food}.')
  23.             if information[food] == 0:
  24.                 information.pop(food)
  25.     command = input()
  26.  
  27. for k, v in sorted(information.items()):
  28.     print(f'{k}: {v}')
  29.  
  30. print(f'All sold: {sold_quantity} goods')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement