Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def index_valid(any_index, any_list):
- if 0 <= any_index < len(any_list):
- return True
- return False
- pirate_ship = list(map(int, input().split(">")))
- warship = list(map(int, input().split(">")))
- max_health = int(input())
- is_over = False
- while True:
- command = input().split()
- if "Retire" in command:
- break
- elif "Fire" in command and index_valid(int(command[1]), warship):
- index = int(command[1])
- value = int(command[2])
- if warship[index] - value <= 0:
- is_over = True
- print("You won! The enemy ship has sunken.")
- break
- warship[index] -= value
- elif "Defend" in command and index_valid(int(command[1]), pirate_ship) and index_valid(int(command[2]), pirate_ship):
- index1 = int(command[1])
- index2 = int(command[2])
- value = int(command[3])
- for i in range(index1, index2 +1):
- if pirate_ship[i] - value <= 0:
- is_over = True
- print("You lost! The pirate ship has sunken.")
- break
- pirate_ship[i] -= value
- if is_over:
- break
- elif "Repair" in command and index_valid(int(command[1]), pirate_ship):
- index = int(command[1])
- value = int(command[2])
- if pirate_ship[index] + value >= max_health:
- pirate_ship[index] = max_health
- else:
- pirate_ship[index] += value
- elif "Status" in command:
- repair_needed = len([n for n in pirate_ship if n < 0.2 * max_health])
- print(f"{repair_needed} sections need repair.")
- if not is_over:
- print(f"Pirate ship status: {sum(pirate_ship)}\nWarship status: {sum(warship)}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement