Advertisement
viligen

man_o_war_+def

Oct 23rd, 2021
886
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. def index_valid(any_index, any_list):
  2.     if 0 <= any_index < len(any_list):
  3.         return True
  4.     return False
  5.  
  6.  
  7. pirate_ship = list(map(int, input().split(">")))
  8. warship = list(map(int, input().split(">")))
  9. max_health = int(input())
  10. is_over = False
  11.  
  12. while True:
  13.     command = input().split()
  14.     if "Retire" in command:
  15.         break
  16.     elif "Fire" in command and index_valid(int(command[1]), warship):
  17.         index = int(command[1])
  18.         value = int(command[2])
  19.         if warship[index] - value <= 0:
  20.             is_over = True
  21.             print("You won! The enemy ship has sunken.")
  22.             break
  23.         warship[index] -= value
  24.     elif "Defend" in command and index_valid(int(command[1]), pirate_ship) and index_valid(int(command[2]), pirate_ship):
  25.         index1 = int(command[1])
  26.         index2 = int(command[2])
  27.         value = int(command[3])
  28.         for i in range(index1, index2 +1):
  29.             if pirate_ship[i] - value <= 0:
  30.                 is_over = True
  31.                 print("You lost! The pirate ship has sunken.")
  32.                 break
  33.             pirate_ship[i] -= value
  34.         if is_over:
  35.             break
  36.     elif "Repair" in command and index_valid(int(command[1]), pirate_ship):
  37.         index = int(command[1])
  38.         value = int(command[2])
  39.         if pirate_ship[index] + value >= max_health:
  40.             pirate_ship[index] = max_health
  41.         else:
  42.             pirate_ship[index] += value
  43.     elif "Status" in command:
  44.         repair_needed = len([n for n in pirate_ship if n < 0.2 * max_health])
  45.         print(f"{repair_needed} sections need repair.")
  46. if not is_over:
  47.     print(f"Pirate ship status: {sum(pirate_ship)}\nWarship status: {sum(warship)}")
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement