Advertisement
bl00dt3ars

02. Treasure Hunt (Stoqnow)

Jul 3rd, 2021
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. def check_index(list_name: list, index_num: int):
  2.     if 0 <= index_num < len(list_name):
  3.         return True
  4.     else:
  5.         return False
  6.  
  7.  
  8. initial_treasure_list = input().split('|')
  9. command = input()
  10.  
  11. while not command == 'Yohoho!':
  12.     command = command.split()
  13.     command_type = command[0]
  14.     if command_type == 'Loot':
  15.         for index in range(1, len(command)):
  16.             item = command[index]
  17.             if item not in initial_treasure_list:
  18.                 initial_treasure_list.insert(0, item)
  19.     elif command_type == 'Drop':
  20.         given_index = int(command[1])
  21.         if check_index(initial_treasure_list, given_index):
  22.             initial_treasure_list.append(initial_treasure_list.pop(given_index))
  23.     elif command_type == 'Steal':
  24.         stolen_items_list = []
  25.         given_num = int(command[1])
  26.         if len(initial_treasure_list) <= given_num:
  27.             stolen_items_list = initial_treasure_list
  28.             initial_treasure_list = []
  29.         else:
  30.             stolen_items_list = initial_treasure_list[len(initial_treasure_list) - given_num:]
  31.             initial_treasure_list = initial_treasure_list[:len(initial_treasure_list) - given_num]
  32.         print(', '.join(stolen_items_list))
  33.     command = input()
  34.  
  35. total_sum = 0
  36. if not initial_treasure_list:
  37.     print('Failed treasure hunt.')
  38. else:
  39.     for element in initial_treasure_list:
  40.         total_sum += len(element)
  41.     average_gain = total_sum / len(initial_treasure_list)
  42.     print(f"Average treasure gain: {average_gain:.2f} pirate credits.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement