GeorgiLukanov87

pirate_warship

Jun 18th, 2022 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.90 KB | None | 0 0
  1. pirate = list(map(int, input().split('>')))
  2. warship = list(map(int, input().split('>')))
  3. max_health_cap = int(input())
  4. command = input()
  5. finished_battle = False
  6. while not command == 'Retire':
  7.     command = command.split()
  8.  
  9.     if command[0] == 'Fire':
  10.         index = int(command[1])
  11.         damage = int(command[2])
  12.         if 0 <= index <= len(warship):
  13.             warship[index] -= damage
  14.             if warship[index] <= 0:
  15.                 print('You won! The enemy ship has sunken.')
  16.                 finished_battle = True
  17.                 break
  18.         else:
  19.             command = input()
  20.             continue
  21.  
  22.     elif command[0] == 'Defend':
  23.         start_index = int(command[1])
  24.         end_index = int(command[2])
  25.         damage = int(command[3])
  26.         if start_index >= 0 and start_index <= end_index and end_index < len(pirate):
  27.             for shot in range(start_index, end_index + 1):
  28.                 pirate[shot] -= damage
  29.                 if pirate[shot] <= 0:
  30.                     print("You lost! The pirate ship has sunken.")
  31.                     finished_battle = True
  32.                     break
  33.         else:
  34.             command = input()
  35.             continue
  36.  
  37.     elif command[0] == 'Repair':
  38.         index = int(command[1])
  39.         health = int(command[2])
  40.         if 0 <= index < len(pirate):
  41.             pirate[index] += health
  42.             if pirate[index] > max_health_cap:
  43.                 pirate[index] = max_health_cap
  44.         else:
  45.             command = input()
  46.             continue
  47.  
  48.     elif command[0] == 'Status':
  49.         sections_counter = 0
  50.         for section in pirate:
  51.             if section < max_health_cap * 0.20:
  52.                 sections_counter += 1
  53.         print(f'{sections_counter} sections need repair.')
  54.  
  55.     command = input()
  56.  
  57. if not finished_battle:
  58.     print(f"Pirate ship status: {sum(pirate)}")
  59.     print(f"Warship status: {sum(warship)}")
Add Comment
Please, Sign In to add comment