aneliabogeva

06 Shopping Exam

Jul 3rd, 2019
129
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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}")
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×