SHARE
TWEET

Man O War

ChynaBG Feb 27th, 2020 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pirate_ship = list(map(int, input().split('>')))
  2. warship = list(map(int, input().split('>')))
  3. max_health = int(input())
  4. lost = False
  5. command = input()
  6.  
  7. while command != 'Retire':
  8.     tokens = command.split(' ')
  9.     if tokens[0] == 'Fire':
  10.         idx = int(tokens[1])
  11.         damage = int(tokens[2])
  12.         if idx >= 0 and idx < len(warship):
  13.             warship[idx] -= damage
  14.             if warship[idx] <= 0:
  15.                 print('You won! The enemy ship has sunken.')
  16.                 lost = True
  17.                 break
  18.     elif tokens[0] == 'Defend':
  19.         start_idx = int(tokens[1])
  20.         end_idx = int(tokens[2])
  21.         damage = int(tokens[3])
  22.         if start_idx >= 0 and start_idx < len(pirate_ship) and end_idx >= 0 and end_idx < len(pirate_ship):
  23.             for idx in range(start_idx, end_idx + 1):
  24.                 pirate_ship[idx] -= damage
  25.                 if pirate_ship[idx] <= 0:
  26.                     print('You lost! The pirate ship has sunken.')
  27.                     lost = True
  28.                     break
  29.             if lost:
  30.                 break
  31.     elif tokens[0] == 'Repair':
  32.         idx = int(tokens[1])
  33.         health = int(tokens[2])
  34.         if idx >= 0 and idx < len(pirate_ship):
  35.             if pirate_ship[idx] + health > max_health:
  36.                 health = max_health - pirate_ship[idx]
  37.             pirate_ship[idx] += health
  38.     elif tokens[0] == 'Status':
  39.         minimum = max_health * 0.2
  40.         count = len([x for x in pirate_ship if x < minimum])
  41.         print(f'{count} sections need repair.')
  42.  
  43.     command = input()
  44. if not lost:
  45.     print(f'Pirate ship status: {sum(pirate_ship)}')
  46.     print(f'Warship status: {sum(warship)}')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top