Advertisement
George_Ivanov05

Salam alekum

Jul 6th, 2021
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. pirate_ship = [int(i) for i in input().split(">")]
  2. warship = [int(i) for i in input().split(">")]
  3. max_health_capacity = int(input())
  4. command = input().split()
  5.  
  6. stalemate = True
  7.  
  8. while not command[0] == "Retire":
  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.                 stalemate = False
  17.                 break
  18.     elif command[0] == "Defend":
  19.         start_index = int(command[1])
  20.         end_index = int(command[2])
  21.         damage = int(command[3])
  22.         if 0 <= start_index < len(pirate_ship) and 0 <= end_index < len(pirate_ship):
  23.             for i in range(start_index, end_index + 1):
  24.                 pirate_ship[i] -= damage
  25.                 if pirate_ship[i] <= 0:
  26.                     print("You lost! The pirate ship has sunken.")
  27.                     stalemate = False
  28.                     break
  29.     elif command[0] == "Repair":
  30.         index = int(command[1])
  31.         health = int(command[2])
  32.         if 0 <= index < len(pirate_ship):
  33.             if pirate_ship[index] + health <= max_health_capacity:
  34.                 pirate_ship[index] += health
  35.             else:
  36.                 pirate_ship[index] = max_health_capacity
  37.     elif command[0] == "Status":
  38.         sections_that_need_repair = [el for el in pirate_ship if el < max_health_capacity / 5]
  39.         print(f"{len(sections_that_need_repair)} sections need repair.")
  40.  
  41.     command = input().split()
  42.  
  43. if stalemate:
  44.     print(f"Pirate ship status: {sum(pirate_ship)}")
  45.     print(f"Warship status: {sum(warship)}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement