Advertisement
ChynaBG

Treasure Hunt

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