sievrebo

Exam Shopping

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