Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- treasure_chest = [el for el in input().split("|")]
- commands = input()
- stealed_items = []
- is_empty = False
- while not commands == "Yohoho!":
- command = commands.split()[0]
- if command == "Loot":
- for item in commands.split():
- if item not in treasure_chest and not item == "Loot":
- treasure_chest.insert(0, item)
- elif command == "Drop":
- index = int(commands.split()[1])
- for i in range(len(treasure_chest)):
- if index == i:
- treasure_chest.append(treasure_chest[index])
- treasure_chest.remove(treasure_chest[index])
- elif command == "Steal":
- count = int(commands.split()[1])
- for el in range(1, count + 1):
- if len(treasure_chest) >= count:
- last_el = treasure_chest[-1]
- treasure_chest.remove(last_el)
- stealed_items.insert(0, last_el)
- else:
- if not len(treasure_chest) == 0:
- for stealed in treasure_chest[::-1]:
- stealed_items.insert(0, stealed)
- treasure_chest.clear()
- is_empty = True
- break
- print(", ".join(stealed_items))
- commands = input()
- if is_empty:
- print("Failed treasure hunt.")
- else:
- total_len = 0
- for el in treasure_chest:
- len_of_each_el = len(el)
- total_len += len_of_each_el
- average_treasure_gain = total_len / len(treasure_chest)
- print(f"Average treasure gain: {average_treasure_gain:.2f} pirate credits.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement