Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pirate_ship = input().split('>')
- num_pirate_ship = list(map(lambda x: int(x), pirate_ship))
- warship_list = input().split('>')
- num_warship = list(map(lambda x: int(x), warship_list))
- maximum_health = int(input())
- commands = input()
- is_stalemate = True
- while commands != 'Retire':
- tokens = commands.split(' ')
- action = tokens[0]
- if action == 'Fire':
- index = int(tokens[1])
- damage = int(tokens[2])
- if 0 <= index < len(num_warship):
- num_warship[index] -= damage
- if num_warship[index] <= 0:
- print('You won! The enemy ship has sunken.')
- is_stalemate = False
- break
- elif action == 'Defend':
- start_index = int(tokens[1])
- end_index = int(tokens[2])
- damage = int(tokens[3])
- if 0 <= start_index < (len(num_pirate_ship) - 1) and 1 <= end_index < len(
- num_pirate_ship) and start_index != end_index:
- if end_index < (len(num_pirate_ship) - 1):
- range_damaged = num_pirate_ship[start_index:end_index + 1]
- num_pirate_ship = [x - damage for x in num_pirate_ship[start_index:end_index + 1]] + num_pirate_ship[end_index + 1:]
- elif end_index == (len(num_pirate_ship)-1):
- range_damaged = num_pirate_ship[start_index:end_index + 1]
- num_pirate_ship = [x - damage for x in num_pirate_ship[start_index:end_index + 1]] + num_pirate_ship[
- end_index + 1:]
- if [x for x in num_pirate_ship if x <= 0]:
- print(f'You lost! The pirate ship has sunken.')
- is_stalemate = False
- break
- elif action == 'Repair':
- index = int(tokens[1])
- health = int(tokens[2])
- if 0 <= index < len(num_pirate_ship):
- num_pirate_ship[index] += health
- if num_pirate_ship[index] > maximum_health:
- num_pirate_ship[index] = maximum_health
- elif action == 'Status':
- min_health = maximum_health * 0.2
- countered = [x for x in num_pirate_ship if x < min_health]
- unhealthy = len(countered)
- print(f'{unhealthy:.0f} sections need repair.')
- commands = input()
- if is_stalemate:
- pirate_ship_sum = sum(num_pirate_ship)
- warship_sum = sum(num_warship)
- print(f'Pirate ship status: {pirate_ship_sum:.0f}')
- print(f'Warship status: {warship_sum:.0f}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement