ramsess90

06_exam_shopping

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