Advertisement
Guest User

Untitled

a guest
Feb 6th, 2020
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.06 KB | None | 0 0
  1. pirates = list(map(lambda x: int(x), input().split(">")))
  2. warship = list(map(lambda x: int(x), input().split(">")))
  3. max_health = int(input())
  4. check = True
  5. win_check = False
  6.  
  7. while True:
  8.  
  9.     commands = input()
  10.     if commands == "Retire":
  11.         break
  12.  
  13.     if win_check:
  14.         break
  15.  
  16.     actions = commands.split(" ")
  17.  
  18.  
  19.     if actions[0] == "Fire":
  20.         index = int(actions[1])
  21.         damage = int(actions[2])
  22.  
  23.  
  24.         if index < len(warship) and warship[index] >= 0:
  25.             warship[index] -= damage
  26.             if warship[index] <= 0:
  27.                 print("You won! The enemy ship has sunken.")
  28.                 check = False
  29.                 win_check = True
  30.                 break
  31.  
  32.  
  33.     elif actions[0] == "Defend":
  34.         start_index = int(actions[1])
  35.         end_index = int(actions[2])
  36.         damage = int(actions[3])
  37.  
  38.         if start_index > len(pirates) or end_index > len(pirates):
  39.             continue
  40.  
  41.         if start_index < len(pirates) and end_index < len(pirates):
  42.  
  43.             for j in range(0, len(pirates)):
  44.  
  45.                 if start_index >= j or end_index >= j:
  46.                     pirates[j] -= damage
  47.  
  48.                     if pirates[j] <= 0:
  49.                         print("You lost! The pirate ship has sunken.")
  50.                         check = False
  51.                         win_check = True
  52.                         break
  53.  
  54.     elif actions[0] == "Repair":
  55.         index = int(actions[1])
  56.         health_gain = int(actions[2])
  57.  
  58.         if index < len(pirates) and index >= 0:
  59.             pirates[index] += health_gain
  60.  
  61.             if pirates[index] > max_health:
  62.                 pirates[index] = max_health
  63.  
  64.  
  65.     elif actions[0] == "Status":
  66.         repairs_ships = 0
  67.  
  68.         for k in range(0, len(pirates)):
  69.             current_health = pirates[k]
  70.  
  71.             if current_health < max_health * 0.2:
  72.                 repairs_ships += 1
  73.  
  74.         print(f"{repairs_ships} sections need repair.")
  75.  
  76. if check:
  77.     print(f"Pirate ship status: {sum(pirates)}")
  78.     print(f"Warship status: {sum(warship)}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement