Sabev

Exam Shopping

Jan 16th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. dict = {}
  2.  
  3. action = 'stock'
  4.  
  5. while True:
  6.     inp = input()
  7.     if inp == 'shopping time':
  8.         action = 'buy'
  9.         continue
  10.     elif inp == 'exam time':
  11.         for key, val in dict.items():
  12.             if val>0:
  13.                 print(f'{key} -> {val}')
  14.         break
  15.  
  16.     (do, product, quantity) = inp.split(' ')
  17.  
  18.     if action == 'stock':
  19.         if product in dict:
  20.             dict[product] += int(quantity)
  21.         else:
  22.             dict[product] = int(quantity)
  23.     elif action == 'buy':
  24.         if product in dict:
  25.             if dict[product] >= int(quantity):
  26.                 dict[product] -= int(quantity)
  27.             elif dict[product] == 0:
  28.                 print(f"{product} out of stock")
  29.             else:
  30.                 dict[product] = 0
  31.         else:
  32.             print(f"{product} doesn't exist")
Advertisement
Add Comment
Please, Sign In to add comment