Advertisement
viligen

treasure_hunt

Oct 20th, 2021
1,451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. loot = input().split("|")
  2.  
  3. while True:
  4.     command = input().split()
  5.  
  6.     if "Yohoho!" in command:
  7.         break
  8.     elif "Loot" in command:
  9.         items = command[1:]
  10.         for item in items:
  11.             if item not in loot:
  12.                 loot.insert(0, item)
  13.     elif "Drop" in command and 0 <= int(command[1]) < len(loot):
  14.         removed = loot.pop(int(command[1]))
  15.         loot.append(removed)
  16.     elif "Steal" in command and int(command[1]) > 0:
  17.         count = int(command[1])
  18.         stolen = loot[-count:]
  19.         loot = loot[:-count]
  20.         print(", ".join(stolen))
  21. if len(loot) == 0:
  22.     print("Failed treasure hunt.")
  23. else:
  24.     lens = [int(len(s)) for s in loot]
  25.     average = sum(lens)/len(loot)
  26.     print(f"Average treasure gain: {average:.2f} pirate credits.")
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement