# man_o_war

Oct 19th, 2021
720
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. list_pirate_ship = list(map(int, input().split(">")))
2. list_warship = list(map(int, input().split(">")))
3. max_health_capacity = int(input())
4. is_over = False
5. while True:
6.     command = input().split()
7.     if "Retire" in command:
8.         break
9.
10.     elif "Fire" in command and 0 <= int(command[1]) < len(list_warship):
11.         if int(command[2]) - list_warship[int(command[1])] >= 0:
12.             print("You won! The enemy ship has sunken.")
13.             is_over = True
14.             break
15.         list_warship[int(command[1])] -= int(command[2])
16.     elif "Defend" in command and 0 <= int(command[1]) < len(list_pirate_ship) and 0 <= int(command[2])\
17.             < len(list_pirate_ship):
18.         if int(command[1]) <= int(command[2]):
19.             for index in range(int(command[1]), int(command[2]) + 1):
20.                 if list_pirate_ship[index] - int(command[3]) <= 0:
21.                     print("You lost! The pirate ship has sunken.")
22.                     is_over = True
23.                     break
24.                 list_pirate_ship[index] -= int(command[3])
25.
26.             if is_over:
27.                 break
28.         elif int(command[1]) > int(command[2]):
29.             for index in range(int(command[2]), int(command[1]) + 1):
30.                 if list_pirate_ship[index] - int(command[3]) <= 0:
31.                     print("You lost! The pirate ship has sunken.")
32.                     is_over = True
33.                     break
34.                 list_pirate_ship[index] -= int(command[3])
35.             if is_over:
36.                 break
37.     elif "Repair" in command and (0 <= int(command[1]) < len(list_pirate_ship)):
38.         if int(command[2]) + list_pirate_ship[int(command[1])] <= max_health_capacity:
39.             list_pirate_ship[int(command[1])] += int(command[2])
40.         else:
41.             list_pirate_ship[int(command[1])] = max_health_capacity
42.     elif "Status" in command:
43.         repair_needed = len([n for n in list_pirate_ship if n < (0.2 * max_health_capacity)])
44.         print(f"{repair_needed} sections need repair.")
45.
46. if not is_over:
47.     print(f"Pirate ship status: {sum(list_pirate_ship)}\nWarship status: {sum(list_warship)}")
48.
RAW Paste Data