Advertisement
pacho_the_python

Untitled

Feb 15th, 2022
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. treasure_chest = input().split("|")
  2.  
  3. stolen_goods = []
  4. event = input().split(" ")
  5.  
  6. while True:
  7.     if event[0] == "Yohoho!":
  8.         break
  9.  
  10.     if event[0] == "Loot":
  11.         event.remove(event[0])
  12.         for x in event:
  13.             if x not in treasure_chest:
  14.                 treasure_chest.insert(0, x)
  15.  
  16.     elif event[0] == "Drop":
  17.         position = int(event[1])
  18.         if 0 <= position < len(treasure_chest) - 1:
  19.             dropped_item = treasure_chest[position]
  20.             treasure_chest.pop(position)
  21.             treasure_chest.append(dropped_item)
  22.  
  23.     elif event[0] == "Steal":
  24.         for i in range(int(event[1])):
  25.             if len(treasure_chest) == 0:
  26.                 break
  27.             else:
  28.                 stolen_item = treasure_chest[len(treasure_chest) - 1]
  29.                 stolen_goods.append(stolen_item)
  30.                 treasure_chest.remove(stolen_item)
  31.  
  32.     event = input().split(" ")
  33.  
  34. stolen_goods.reverse()
  35.  
  36. treasure_sum = 0
  37. counter = 0
  38.  
  39. if len(treasure_chest) > 0:
  40.     for chest in treasure_chest:
  41.         treasure_sum += len(chest)
  42.         counter += 1
  43.     pirate_profit = treasure_sum / counter
  44.     print(", ".join(stolen_goods))
  45.     print(f"Average treasure gain: {pirate_profit:.2f} pirate credits.")
  46. else:
  47.     print(", ".join(stolen_goods))
  48.     print("Failed treasure hunt.")
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement