Advertisement
aneliabogeva

06 Shopping Exam

Jul 3rd, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. command = input()
  2. names_dict = {}
  3.  
  4. while not command == 'shopping time':
  5. action, key, value = command.split(" ")
  6. value = int(value)
  7. if key in names_dict:
  8. names_dict[key] += value
  9. else:
  10. names_dict[key] = value
  11.  
  12. command = input()
  13.  
  14. command_buy = input()
  15. while not command_buy == 'exam time':
  16. action, key, value = command_buy.split(" ")
  17. quantity = int(value)
  18. if key in names_dict:
  19. if quantity <= 0:
  20. print(f"{key} out of stock")
  21. elif quantity > names_dict[key]:
  22. quantity = 0
  23. else:
  24. names_dict[key] -= quantity
  25. else:
  26. print(f"{key} doesn't exist")
  27.  
  28. command_buy = input()
  29.  
  30. for key, value in names_dict.items():
  31. print(f"{key} -> {value}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement