sievrebo

Exam Shopping

Jul 9th, 2019
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. data_list = input().split(' ')
  2. stock_dict = {}
  3.  
  4. while data_list[0] != "shopping":
  5.  
  6.     product = data_list[1]
  7.     quantity = int(data_list[2])
  8.  
  9.     if product in stock_dict:
  10.         stock_dict[product] += quantity
  11.     else:
  12.         stock_dict[product] = quantity
  13.  
  14.     data_list = list(input().split(' '))
  15.  
  16. data_list = input().split(' ')
  17. while data_list[0] == "buy":
  18.  
  19.     product = data_list[1]
  20.     quantity = int(data_list[2])
  21.  
  22.     if product in stock_dict:
  23.         if stock_dict[product] == 0:
  24.             print(f"{product} out of stock")
  25.         else:
  26.             stock_dict[product] -= quantity
  27.  
  28.     elif product not in stock_dict:
  29.         print(f"{product} doesn't exist")
  30.  
  31.     data_list = list(input().split(' '))
  32.  
  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