Advertisement
Darlexbg

03. Man-O-War

Sep 27th, 2020
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.96 KB | None | 0 0
  1. pirate_ship = list(map(int, input().split(">")))
  2. warship = list(map(int, input().split(">")))
  3. maximum_health = int(input())
  4. is_sunken = False
  5.  
  6. while True:
  7.     command = input().split()
  8.     if command[0] == "Retire":
  9.         break
  10.  
  11.     if command[0] == "Fire":
  12.         index = int(command[1])
  13.         damage = int(command[2])
  14.         if len(warship) > index >= 0:
  15.             warship[index] -= damage
  16.             if warship[index] <= 0:
  17.                 print("You won! The enemy ship has sunken.")
  18.                 is_sunken = True
  19.                 break
  20.         if is_sunken:
  21.             break
  22.  
  23.     elif command[0] == "Defend":
  24.         start_index = int(command[1])
  25.         end_index = int(command[2])
  26.         damage = int(command[3])
  27.         if 0 <= start_index < len(pirate_ship) and 0 <= end_index < len(pirate_ship) and damage > 0:
  28.             for i in range(start_index, end_index + 1):
  29.                 pirate_ship[i] -= damage
  30.                 if pirate_ship[i] <= 0:
  31.                     print("You lost! The pirate ship has sunken.")
  32.                     is_sunken = True
  33.                     break
  34.             if is_sunken:
  35.                 break
  36.         if is_sunken:
  37.             break
  38.  
  39.     elif command[0] == "Repair":
  40.         index = int(command[1])
  41.         health = int(command[2])
  42.         if 0 <= index < len(pirate_ship) and health > 0:
  43.             pirate_ship[index] += health
  44.             if pirate_ship[index] > maximum_health:
  45.                 pirate_ship[index] = maximum_health
  46.  
  47.     elif command[0] == "Status":
  48.         counter_for_repair = 0
  49.     low_health = maximum_health * 0.20
  50.         for section in pirate_ship:
  51.             if section < low_health:
  52.                 counter_for_repair += 1
  53.         print(f"{counter_for_repair} sections need repair.")
  54.  
  55. if not is_sunken:
  56.     pirate_ship_sum = sum(pirate_ship)
  57.     warship_sum = sum(warship)
  58.  
  59.     print(f"Pirate ship status: {pirate_ship_sum}")
  60.     print(f"Warship status: {warship_sum}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement