Advertisement
snow27

Exam_Inverotory

Oct 31st, 2020
710
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. def check_item_exist(check_item, all_items):
  2.     all_items = set(all_items)
  3.     if check_item in all_items:
  4.         return True
  5.     else:
  6.         return False
  7.  
  8.  
  9. items = input().split(", ")
  10.  
  11. command = input()
  12.  
  13.  
  14. while not command == "Craft!":
  15.     type_command = command.split(" - ")[0]
  16.     item = command.split(" - ")[1]
  17.     is_exist = check_item_exist(item, items)
  18.     if type_command == "Collect" and not is_exist:
  19.         items.append(item)
  20.     elif type_command == "Drop" and is_exist:
  21.         items.remove(item)
  22.     elif type_command == "Combine Items":
  23.         old_item = item.split(":")[0]
  24.         new_item = item.split(":")[1]
  25.         is_exist = check_item_exist(old_item, items)
  26.         if is_exist:
  27.             index = items.index(old_item)
  28.             items.insert(index + 1, new_item)
  29.     elif type_command == "Renew" and is_exist:
  30.         index = items.index(item)
  31.         x = items.pop(index)
  32.         items.append(x)
  33.     command = input()
  34.  
  35. print(", ".join(items))
  36.  
  37.  
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement