Advertisement
webbersof

inventory

Feb 11th, 2022
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. def collect_func(data, item):
  2. if item not in data:
  3. data.append(item)
  4.  
  5. return data
  6.  
  7. def drop_func(data, item):
  8. if item in data:
  9. data.remove(item)
  10.  
  11. return data
  12.  
  13. def combine_items_func(data, items):
  14. items = items.split(':')
  15. old_element = items[0]
  16. new_element = items[1]
  17.  
  18. if old_element in data:
  19. index_old_element = data.index(old_element)
  20. data.insert(index_old_element + 1, new_element)
  21.  
  22. return data
  23.  
  24. def renew_func(data, item):
  25. if item in data:
  26. data.remove(item)
  27. data.append(item)
  28.  
  29. return data
  30.  
  31. def inventory(data):
  32.  
  33. while True:
  34. command = input().split(' - ')
  35.  
  36. if command[0] == 'Craft!':
  37. print(', '.join(data))
  38. break
  39.  
  40. current_command = command[0]
  41. item = command[1]
  42.  
  43. if current_command == 'Collect':
  44. data = collect_func(data, item)
  45. elif current_command == 'Drop':
  46. data = drop_func(data, item)
  47. elif current_command == 'Combine Items':
  48. data = combine_items_func(data, item)
  49. elif current_command == 'Renew':
  50. data = renew_func(data, item)
  51.  
  52. info = input().split(', ')
  53. inventory(info)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement