Advertisement
George_Ivanov05

zadacha

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