Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- treasure_chest = input().split('|')
- command_input = input()
- stolen_list = []
- while command_input != 'Yohoho!':
- command_args = command_input.split()
- command = command_args[0]
- if command == 'Loot':
- items = command_args[1:]
- for item in items:
- if item not in treasure_chest:
- treasure_chest.insert(0, item)
- elif command == 'Drop':
- index = int(command_args[1])
- if index < 0 or index >= len(treasure_chest):
- command_input = input()
- continue
- removed_item = treasure_chest.pop(index)
- treasure_chest.append(removed_item)
- elif command == 'Steal':
- number = int(command_args[1])
- if number >= len(treasure_chest):
- number = len(treasure_chest)
- idx = 0
- else:
- idx = len(treasure_chest) - number
- stolen_list = treasure_chest[idx:idx+number:]
- del treasure_chest[idx:idx+number:]
- if any(stolen_list):
- print(', '.join(stolen_list))
- command_input = input()
- length = [len(s) for s in treasure_chest]
- if len(treasure_chest) > 0:
- sum_length = sum(length) / len(treasure_chest)
- print(f'Average treasure gain: {sum_length:.2f} pirate credits.')
- else:
- print('Failed treasure hunt.')
Advertisement
Add Comment
Please, Sign In to add comment