# 02.Treasure Hunt

Jul 8th, 2021
967
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. treasure_chest = [el for el in input().split("|")]
2. commands = input()
3. stealed_items = []
4. is_empty = False
5.
6. while not commands == "Yohoho!":
7.     command = commands.split()[0]
8.     if command == "Loot":
9.         for item in commands.split():
10.             if item not in treasure_chest and not item == "Loot":
11.                 treasure_chest.insert(0, item)
12.
13.     elif command == "Drop":
14.         index = int(commands.split()[1])
15.         for i in range(len(treasure_chest)):
16.             if index == i:
17.                 treasure_chest.append(treasure_chest[index])
18.                 treasure_chest.remove(treasure_chest[index])
19.
20.     elif command == "Steal":
21.         count = int(commands.split()[1])
22.         for el in range(1, count + 1):
23.             if len(treasure_chest) >= count:
24.                 last_el = treasure_chest[-1]
25.                 treasure_chest.remove(last_el)
26.                 stealed_items.insert(0, last_el)
27.             else:
28.                 if not len(treasure_chest) == 0:
29.                     for stealed in treasure_chest[::-1]:
30.                         stealed_items.insert(0, stealed)
31.                     treasure_chest.clear()
32.                     is_empty = True
33.                     break
34.         print(", ".join(stealed_items))
35.     commands = input()
36.
37. if is_empty:
38.     print("Failed treasure hunt.")
39. else:
40.     total_len = 0
41.     for el in treasure_chest:
42.         len_of_each_el = len(el)
43.         total_len += len_of_each_el
44.     average_treasure_gain = total_len / len(treasure_chest)
45.     print(f"Average treasure gain: {average_treasure_gain:.2f} pirate credits.")
RAW Paste Data