bl00dt3ars

03. Man O War

Jul 2nd, 2021 (edited)
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.59 KB | None | 0 0
  1. pirate_ship = [int(el) for el in input().split(">")]
  2. warship = [int(el) for el in input().split(">")]
  3. max_health = int(input())
  4. command = input().split()
  5.  
  6. while not command[0] == "Retire":
  7.     if command[0] == "Fire":
  8.         index = int(command[1])
  9.         damage = int(command[2])
  10.         if 0 <= index < len(warship):
  11.             warship[index] -= damage
  12.             if warship[index] <= 0:
  13.                 print(f"You won! The enemy ship has sunken.")
  14.                 exit()
  15.     elif command[0] == "Defend":
  16.         start_index = int(command[1])
  17.         end_index = int(command[2])
  18.         damage = int(command[3])
  19.         if start_index <= end_index and 0 <= start_index < len(pirate_ship) and 0 <= end_index < len(pirate_ship):
  20.             for i in range(start_index, end_index + 1):
  21.                 pirate_ship[i] -= damage
  22.                 if pirate_ship[i] <= 0:
  23.                     print(f"You lost! The pirate ship has sunken.")
  24.                     exit()
  25.     elif command[0] == "Repair":
  26.         index = int(command[1])
  27.         health = int(command[2])
  28.         if 0 <= index < len(pirate_ship):
  29.             if pirate_ship[index] + health <= max_health:
  30.                 pirate_ship[index] += health
  31.             else:
  32.                 pirate_ship[index] = max_health
  33.     elif command[0] == "Status":
  34.         sections_that_need_repair = [el for el in pirate_ship if el < max_health / 5]
  35.         print(f"{len(sections_that_need_repair)} sections need repair.")
  36.     command = input().split()
  37.  
  38. print(f"Pirate ship status: {sum(pirate_ship)}")
  39. print(f"Warship status: {sum(warship)}")
Add Comment
Please, Sign In to add comment