Advertisement
GeorgiLukanov87

02. Treasure Hunt 100/100

Jun 24th, 2022
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. loot = input().split('|')
  2. command = input()
  3. average_gain = 0
  4.  
  5. while not command == 'Yohoho!':
  6.     command = command.split()
  7.  
  8.     if command[0] == 'Loot':
  9.         command.pop(0)
  10.         for item in command:
  11.             if item in loot:
  12.                 continue
  13.             else:
  14.                 loot.insert(0, item)
  15.  
  16.     elif command[0] == 'Drop':
  17.         index = command[1]
  18.         index = int(index)
  19.         if index >= 0 and index <= len(loot):
  20.             x = loot.pop(index)
  21.             loot.append(x)
  22.         else:
  23.             command = input()
  24.             continue
  25.  
  26.     elif command[0] == 'Steal':
  27.         stolen_items = []
  28.         count = command[1]
  29.         count = int(count)
  30.         counter = 0
  31.         bol = False
  32.        
  33.         for item in range(len(loot) - 1, -1, -1):
  34.             counter += 1
  35.             stolen_items.insert(0, loot[item])
  36.             loot.pop(-1)
  37.             if counter == count:
  38.                 print(', '.join(stolen_items))
  39.                 bol = True
  40.                 break
  41.                
  42.         if not bol:
  43.             print(', '.join(stolen_items))
  44.     command = input()
  45.  
  46. if len(loot) <= 0:
  47.     print(f"Failed treasure hunt.")
  48. else:
  49.     for item in loot:
  50.         average_gain += len(item)
  51.          
  52.     average_gain /= len(loot)
  53.     print(f"Average treasure gain: {average_gain:.2f} pirate credits.")
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement