Advertisement
Guest User

[Python]inventory

a guest
Feb 29th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. collection = input().split(', ')
  2.  
  3. while True:
  4.     tokens = input().split(' - ')
  5.     command = tokens[0]
  6.     if command == 'Craft!':
  7.         print(', '.join(collection))
  8.         break
  9.     elif command == 'Collect':
  10.         item = tokens[1]
  11.         if item not in collection:
  12.             collection.append(item)
  13.     elif command == 'Drop':
  14.         item = tokens[1]
  15.         if item in collection:
  16.             collection.remove(item)
  17.     elif command == 'Combine Items':
  18.         args = tokens[1].split(':')
  19.         old_item = args[0]
  20.         new_item = args[1]
  21.         if old_item in collection:
  22.             for i in range(len(collection)):
  23.                 if collection[i] == old_item:
  24.                     collection.insert(i + 1, new_item)
  25.     elif command == 'Renew':
  26.         item = tokens[1]
  27.         for i in range(len(collection)):
  28.             if collection[i] == item:
  29.                 collection.pop(i)
  30.                 collection.append(item)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement