Advertisement
KameliaiV

Man_o_war

Feb 18th, 2020
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.51 KB | None | 0 0
  1. pirate_ship = input().split('>')
  2. num_pirate_ship = list(map(lambda x: int(x), pirate_ship))
  3. warship_list = input().split('>')
  4. num_warship = list(map(lambda x: int(x), warship_list))
  5.  
  6. maximum_health = int(input())
  7. commands = input()
  8. is_stalemate = True
  9.  
  10. while commands != 'Retire':
  11.     tokens = commands.split(' ')
  12.     action = tokens[0]
  13.     if action == 'Fire':
  14.         index = int(tokens[1])
  15.         damage = int(tokens[2])
  16.         if 0 <= index < len(num_warship):
  17.             num_warship[index] -= damage
  18.             if num_warship[index] <= 0:
  19.                 print('You won! The enemy ship has sunken.')
  20.                 is_stalemate = False
  21.                 break
  22.  
  23.     elif action == 'Defend':
  24.         start_index = int(tokens[1])
  25.         end_index = int(tokens[2])
  26.         damage = int(tokens[3])
  27.         if 0 <= start_index < (len(num_pirate_ship) - 1) and 1 <= end_index < len(
  28.                 num_pirate_ship) and start_index != end_index:
  29.             if end_index < (len(num_pirate_ship) - 1):
  30.                 range_damaged = num_pirate_ship[start_index:end_index + 1]
  31.                 num_pirate_ship = [x - damage for x in num_pirate_ship[start_index:end_index + 1]] + num_pirate_ship[end_index + 1:]
  32.             elif end_index == (len(num_pirate_ship)-1):
  33.                 range_damaged = num_pirate_ship[start_index:end_index + 1]
  34.                 num_pirate_ship = [x - damage for x in num_pirate_ship[start_index:end_index + 1]] + num_pirate_ship[
  35.                                                                                                      end_index + 1:]
  36.             if [x for x in num_pirate_ship if x <= 0]:
  37.                 print(f'You lost! The pirate ship has sunken.')
  38.                 is_stalemate = False
  39.                 break
  40.     elif action == 'Repair':
  41.         index = int(tokens[1])
  42.         health = int(tokens[2])
  43.         if 0 <= index < len(num_pirate_ship):
  44.             num_pirate_ship[index] += health
  45.  
  46.             if num_pirate_ship[index] > maximum_health:
  47.                 num_pirate_ship[index] = maximum_health
  48.  
  49.     elif action == 'Status':
  50.         min_health = maximum_health * 0.2
  51.  
  52.         countered = [x for x in num_pirate_ship if x < min_health]
  53.         unhealthy = len(countered)
  54.         print(f'{unhealthy:.0f} sections need repair.')
  55.     commands = input()
  56.  
  57. if is_stalemate:
  58.     pirate_ship_sum = sum(num_pirate_ship)
  59.     warship_sum = sum(num_warship)
  60.     print(f'Pirate ship status: {pirate_ship_sum:.0f}')
  61.     print(f'Warship status: {warship_sum:.0f}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement