Advertisement
Osiris1002

Treasure Hunt

Feb 14th, 2024
872
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. treasure_chest = input().split("|")
  2. command_data = input()
  3.  
  4. while command_data != 'Yohoho!':
  5.     command, *data = [int(x) if x.isdigit() else x for x in command_data.split()]
  6.  
  7.     if command == "Loot":
  8.         for item in data:
  9.             if item not in treasure_chest:
  10.                 treasure_chest.insert(0, item)
  11.     elif command == "Drop":
  12.         index = data[0]
  13.         if index in range(len(treasure_chest)):
  14.             item = treasure_chest.pop(index)
  15.             treasure_chest.append(item)
  16.  
  17.  
  18.     elif command == "Steal":
  19.         index = -data[0]
  20.         stolen_items = treasure_chest[index:]
  21.         treasure_chest = treasure_chest[:index]
  22.         print(', '.join(stolen_items))
  23.  
  24.     command_data = input()
  25.  
  26. if treasure_chest:
  27.     avr_treasure = sum(len(x) for x in treasure_chest) / len(treasure_chest)
  28.     print(f'Average treasure gain: {avr_treasure:.2f} pirate credits.')
  29.  
  30. else:
  31.     print('Failed treasure hunt.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement