Advertisement
Spocoman

03. Man O War

Nov 12th, 2023 (edited)
789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. pirate_ship = list(map(int, input().split('>')))
  2. war_ship = list(map(int, input().split('>')))
  3. max_section_health = int(input())
  4.  
  5. while True:
  6.     command = input()
  7.     if command == "Retire":
  8.         break
  9.     elif command == "Status":
  10.         count = len([x for x in pirate_ship if x < max_section_health / 5])
  11.         print(f"{count} sections need repair.")
  12.         continue
  13.     command = command.split(' ')
  14.     index = int(command[1])
  15.     if command[0] == "Fire":
  16.         damage = int(command[2])
  17.         if 0 <= index < len(war_ship):
  18.             war_ship[index] -= damage
  19.             if war_ship[index] <= 0:
  20.                 print("You won! The enemy ship has sunken.")
  21.                 war_ship.clear()
  22.                 break
  23.     elif command[0] == "Defend":
  24.         final_index = int(command[2])
  25.         damage = int(command[3])
  26.         if 0 <= index < len(pirate_ship) and 0 <= final_index < len(pirate_ship):
  27.             for i in range(index, final_index + 1):
  28.                 pirate_ship[i] -= damage
  29.                 if pirate_ship[i] <= 0:
  30.                     print("You lost! The pirate ship has sunken.")
  31.                     pirate_ship.clear()
  32.                     exit(0)
  33.     elif command[0] == "Repair":
  34.         health = int(command[2])
  35.         if 0 <= index < len(pirate_ship):
  36.             pirate_ship[index] += health
  37.             if pirate_ship[index] > max_section_health:
  38.                 pirate_ship[index] = max_section_health
  39.  
  40. if len(pirate_ship) > 0 and len(war_ship) > 0:
  41.     print(f"Pirate ship status: {sum(pirate_ship)}\nWarship status: {sum(war_ship)}")
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement