Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pirate_ship = input()
- warship = input()
- health_cap = int(input())
- pirate_ship = [int(x) for x in pirate_ship.split('>')]
- warship = [int(x) for x in warship.split('>')]
- sunk = False
- command = input()
- while command != 'Retire':
- tokens = command.split(' ')
- cmd = tokens[0]
- if cmd == 'Fire':
- idx = int(tokens[1])
- if 0 <= idx < len(warship):
- dmg = int(tokens[2])
- warship[idx] -= dmg
- if warship[idx] <= 0:
- sunk = True
- print('You won! The enemy ship has sunken.')
- break
- elif cmd == 'Defend':
- start_idx = int(tokens[1])
- end_idx = int(tokens[2])
- valid = (0 <= start_idx < len(pirate_ship)) and (0 <= end_idx < len(pirate_ship))
- if valid:
- dmg = int(tokens[3])
- for i in range(start_idx, end_idx + 1):
- pirate_ship[i] -= dmg
- sunk = True if [x for x in pirate_ship if x <= 0] else False
- if sunk:
- print('You lost! The pirate ship has sunken.')
- break
- elif cmd == 'Repair':
- idx = int(tokens[1])
- if 0 <= idx < len(pirate_ship):
- health = int(tokens[2])
- pirate_ship[idx] += health
- if pirate_ship[idx] > health_cap:
- pirate_ship[idx] = health_cap
- elif cmd == 'Status':
- print(f'{len([x for x in pirate_ship if x < health_cap * 0.2])} sections need repair.')
- command = input()
- if not sunk:
- print(f'Pirate ship status: {sum(pirate_ship)}\nWarship status: {sum(warship)}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement