Advertisement
KNenov96

Man O War - Mid Exam Retake

Sep 29th, 2022
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.97 KB | Software | 0 0
  1. pirate_ship = list(map(int, input().split(">")))
  2. warship = list(map(int, input().split(">")))
  3. maximum_health_capacity = int(input())
  4. warning_sections = maximum_health_capacity * 0.2
  5. stalemate = True
  6.  
  7. commands = input()
  8.  
  9. while commands != "Retire":
  10.     current_command = commands.split()[0]
  11.  
  12.     if current_command == "Fire":
  13.         index_for_fire = int(commands.split()[1])
  14.         damage_of_fire = int(commands.split()[2])
  15.         if 0 <= index_for_fire < len(warship):
  16.             warship[index_for_fire] -= damage_of_fire
  17.             if warship[index_for_fire] <= 0:
  18.                 print("You won! The enemy ship has sunken.")
  19.                 stalemate = False
  20.                 break
  21.     elif current_command == "Defend":
  22.         starting_index = int(commands.split()[1])
  23.         ending_index = int(commands.split()[2])
  24.         defend_damage = int(commands.split()[3])
  25.         if 0 <= starting_index and ending_index < len(pirate_ship):
  26.             for making_damage in range(starting_index, ending_index+1):
  27.                 pirate_ship[making_damage] -= defend_damage
  28.                 if pirate_ship[making_damage] <= 0:
  29.                     print("You lost! The pirate ship has sunken.")
  30.                     stalemate = False
  31.                     break
  32.     elif current_command == "Repair":
  33.         index_for_repair = int(commands.split()[1])
  34.         health_gained = int(commands.split()[2])
  35.         if 0 <= index_for_repair < len(pirate_ship):
  36.             pirate_ship[index_for_repair] += health_gained
  37.             if pirate_ship[index_for_repair] > maximum_health_capacity:
  38.                 pirate_ship[index_for_repair] = maximum_health_capacity
  39.     elif current_command == "Status":
  40.         sections_in_danger = [x for x in pirate_ship if x < warning_sections]
  41.         print(f"{len(sections_in_danger)} sections need repair.")
  42.  
  43.     commands = input()
  44.  
  45. if stalemate:
  46.     print(f"Pirate ship status: {sum(pirate_ship)}")
  47.     print(f"Warship status: {sum(warship)}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement