Advertisement
emily_n2

Man O War

Feb 18th, 2020
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.60 KB | None | 0 0
  1. pirate_ship = list(map(int, input().split('>')))
  2. warship = list(map(int,input().split('>')))
  3. Max_health = int(input())
  4.  
  5. Low_level = int(Max_health * 0.2)
  6. end = False
  7.  
  8. command = input()
  9. while command != 'Retire':
  10.     parts = command.split()
  11.     action = parts[0]
  12.     if action == 'Fire':
  13.         index = int(parts[1])
  14.         damage = int(parts[2])
  15.         if 0 <= index < len(warship):
  16.             warship[index] -= damage
  17.             if warship[index] <= 0:
  18.                 print('You won! The enemy ship has sunken.')
  19.                 break
  20.  
  21.     elif action == 'Defend':
  22.         start_index = int(parts[1])
  23.         end_index = int(parts[2])
  24.         damage = int(parts[3])
  25.         if 0 <= start_index <= end_index < len(pirate_ship):
  26.             for i in range(start_index, end_index + 1):
  27.                 pirate_ship[i] -= damage
  28.                 if pirate_ship[i] <= 0:
  29.                     print('You lost! The pirate ship has sunken.')
  30.                     end = True
  31.                     break
  32.         if end:
  33.             break
  34.  
  35.     elif action == 'Repair':
  36.         index = int(parts[1])
  37.         health = int(parts[2])
  38.         if 0 <= index < len(pirate_ship):
  39.             pirate_ship[index] += health
  40.             if pirate_ship[index] > Max_health:
  41.                 pirate_ship[index] = Max_health
  42.  
  43.     elif action == 'Status':
  44.         count = len([x for x in pirate_ship if x < Low_level])  
  45.         print(f'{count} sections need repair.')
  46.     command = input()
  47.  
  48. else:
  49.     print(f'Pirate ship status: {sum(i for i in pirate_ship)}')  
  50.     print(f'Warship status: {sum(i for i in warship)}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement