Advertisement
simeonshopov

Man-O-War

Jan 23rd, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.60 KB | None | 0 0
  1. pirate_ship = input()
  2. warship = input()
  3. health_cap = int(input())
  4.  
  5. pirate_ship = [int(x) for x in pirate_ship.split('>')]
  6. warship = [int(x) for x in warship.split('>')]
  7.  
  8. sunk = False
  9.  
  10. command = input()
  11.  
  12. while command != 'Retire':
  13.     tokens = command.split(' ')
  14.     cmd = tokens[0]
  15.     if cmd == 'Fire':
  16.         idx = int(tokens[1])
  17.         if 0 <= idx < len(warship):
  18.             dmg = int(tokens[2])
  19.             warship[idx] -= dmg
  20.             if warship[idx] <= 0:
  21.                 sunk = True
  22.                 print('You won! The enemy ship has sunken.')
  23.                 break
  24.     elif cmd == 'Defend':
  25.         start_idx = int(tokens[1])
  26.         end_idx = int(tokens[2])
  27.         valid = (0 <= start_idx < len(pirate_ship)) and (0 <= end_idx < len(pirate_ship))
  28.         if valid:
  29.             dmg = int(tokens[3])
  30.             for i in range(start_idx, end_idx + 1):
  31.                 pirate_ship[i] -= dmg
  32.             sunk = True if [x for x in pirate_ship if x <= 0] else False
  33.             if sunk:
  34.                 print('You lost! The pirate ship has sunken.')
  35.                 break
  36.     elif cmd == 'Repair':
  37.         idx = int(tokens[1])
  38.         if 0 <= idx < len(pirate_ship):
  39.             health = int(tokens[2])
  40.             pirate_ship[idx] += health
  41.             if pirate_ship[idx] > health_cap:
  42.                 pirate_ship[idx] = health_cap
  43.     elif cmd == 'Status':
  44.         print(f'{len([x for x in pirate_ship if x < health_cap * 0.2])} sections need repair.')
  45.     command = input()
  46.  
  47. if not sunk:
  48.     print(f'Pirate ship status: {sum(pirate_ship)}\nWarship status: {sum(warship)}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement