Advertisement
simeonshopov

Treasure Hunt

Jan 23rd, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. chest = input().split('|')
  2.  
  3. while True:
  4.     command = input()
  5.     if command == 'Yohoho!':
  6.         break
  7.     else:
  8.         tokens = command.split(' ')
  9.         cmd = tokens[0]
  10.         if cmd == 'Loot':
  11.             new_items = tokens[1:]
  12.             [chest.insert(0, x) for x in new_items if x not in chest]
  13.         elif cmd == 'Drop':
  14.             idx = int(tokens[1])
  15.             if 0 <= idx < len(chest):
  16.                 chest.append(chest.pop(idx))
  17.         elif cmd == 'Steal':
  18.             count = int(tokens[1])
  19.             if len(chest) <= count:
  20.                 print(', '.join(chest))
  21.                 chest = []
  22.             else:
  23.                 pos = len(chest) - count
  24.                 print(', '.join(chest[pos:]))
  25.                 chest = chest[:pos]
  26.  
  27. if chest:
  28.     gain = sum([len(x) for x in chest]) / len(chest)
  29.     print(f'Average treasure gain: {gain:.2f} pirate credits.')
  30. else:
  31.     print('Failed treasure hunt.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement