Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- chest = input().split('|')
- while True:
- command = input()
- if command == 'Yohoho!':
- break
- else:
- tokens = command.split(' ')
- cmd = tokens[0]
- if cmd == 'Loot':
- new_items = tokens[1:]
- [chest.insert(0, x) for x in new_items if x not in chest]
- elif cmd == 'Drop':
- idx = int(tokens[1])
- if 0 <= idx < len(chest):
- chest.append(chest.pop(idx))
- elif cmd == 'Steal':
- count = int(tokens[1])
- if len(chest) <= count:
- print(', '.join(chest))
- chest = []
- else:
- pos = len(chest) - count
- print(', '.join(chest[pos:]))
- chest = chest[:pos]
- if chest:
- gain = sum([len(x) for x in chest]) / len(chest)
- print(f'Average treasure gain: {gain:.2f} pirate credits.')
- else:
- print('Failed treasure hunt.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement