Advertisement
Spocoman

02. Treasure Hunt

Nov 10th, 2023
852
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. chest = input().split('|')
  2. command = input()
  3.  
  4. while command != "Yohoho!":
  5.     tokens = command.split(' ')
  6.     command = tokens[0]
  7.     if command == "Loot":
  8.         for i in range(1, len(tokens)):
  9.             if tokens[i] not in chest:
  10.                 chest.insert(0, tokens[i])
  11.     elif command == "Drop":
  12.         index = int(tokens[1])
  13.         if 0 <= index < len(chest):
  14.             chest.append(chest.pop(index))
  15.     elif command == "Steal":
  16.         count = int(tokens[1])
  17.         stolen_chest = chest[-count:]
  18.         chest = chest[: - count]
  19.         print(", ".join(stolen_chest))
  20.  
  21.     command = input()
  22.  
  23. if len(chest) == 0:
  24.     print("Failed treasure hunt.")
  25. else:
  26.     average_gain = len(''.join(chest)) / len(chest)
  27.     print(f"Average treasure gain: {average_gain:.2f} pirate credits.")
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement