bl00dt3ars

02. Treasure Hunt

Jul 1st, 2021 (edited)
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. loot = input().split("|")
  2. command = input().split()
  3.  
  4. while not command[0] == "Yohoho!":
  5.     if command[0] == "Loot":
  6.         for el in range(1, len(command)):
  7.             if command[el] not in loot:
  8.                 loot.insert(0, command[el])
  9.     elif command[0] == "Drop":
  10.         if 0 <= int(command[1]) < len(loot):
  11.             loot.append(loot.pop(int(command[1])))
  12.     elif command[0] == "Steal":
  13.         if int(command[1]) >= len(loot):
  14.             print(", ".join(loot))
  15.             loot = []
  16.         else:
  17.             print(", ".join(loot[len(loot) - int(command[1]):]))
  18.             loot = loot[:len(loot) - int(command[1])]
  19.     command = input().split()
  20.  
  21. if len(loot) == 0:
  22.     print("Failed treasure hunt.")
  23. else:
  24.     average_gain = sum([len(el) for el in loot]) / len(loot)
  25.     print(f"Average treasure gain: {average_gain:.2f} pirate credits.")
Add Comment
Please, Sign In to add comment