sievrebo

Exam Shopping

Jul 9th, 2019
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. data_list = input().split(' ')
  2.  
  3. stock_dict = {}
  4.  
  5. while data_list[0] != "shopping":
  6.  
  7.     product = data_list[1]
  8.     quantity = int(data_list[2])
  9.  
  10.     if product in stock_dict:
  11.         stock_dict[product] += quantity
  12.     else:
  13.         stock_dict[product] = quantity
  14.  
  15.     data_list = list(input().split(' '))
  16.  
  17. data_list = input().split(' ')
  18. while data_list[0] == "buy":
  19.  
  20.     product = data_list[1]
  21.     quantity = int(data_list[2])
  22.  
  23.     if product in stock_dict:
  24.         if stock_dict[product] == 0:
  25.             print(f"{product} out of stock")
  26.         else:
  27.             stock_dict[product] -= quantity
  28.  
  29.     else:
  30.         print(f"{product} doesn't exist")
  31.  
  32.     data_list = list(input().split(' '))
  33.  
  34. for key, value in stock_dict.items():
  35.     if value > 0:
  36.         print(f"{key} -> {value}")
Advertisement
Add Comment
Please, Sign In to add comment