Advertisement
Guest User

Man O War

a guest
Feb 27th, 2020
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. pirate_ship = list(map(int, input().split('>')))
  2. warship = list(map(int, input().split('>')))
  3. max_health = int(input())
  4. game_over = False
  5.  
  6.  
  7. def is_valid(index, limit):
  8. return 0 <= index < limit
  9.  
  10.  
  11. line = input().split()
  12. while line[0] != 'Retire' and not game_over:
  13. command = line[0]
  14. if command == 'Fire':
  15. index = int(line[1])
  16. damage = int(line[2])
  17. if is_valid(index, len(warship)):
  18. warship[index] -= damage
  19. if warship[index] <= 0:
  20. print('You won! The enemy ship has sunken.')
  21. game_over = True
  22. break
  23. elif command == 'Defend':
  24. index1 = int(line[1])
  25. index2 = int(line[2])
  26. damage = int(line[3])
  27. if is_valid(index1, len(pirate_ship)) and is_valid(index2, len(pirate_ship)):
  28. for i in range(index1, index2 + 1):
  29. pirate_ship[i] -= damage
  30. if pirate_ship[i] <= 0:
  31. print('You lost! The pirate ship has sunken.')
  32. game_over = True
  33. break
  34. elif command == 'Repair':
  35. index = int(line[1])
  36. health = int(line[2])
  37. if is_valid(index, len(pirate_ship)):
  38. pirate_ship[index] += health
  39. if pirate_ship[index] > max_health:
  40. pirate_ship[index] = max_health
  41. else:
  42. counter = 0
  43. for x in pirate_ship:
  44. if x < max_health * 0.2:
  45. counter += 1
  46. print(f'{counter} sections need repair.')
  47.  
  48. line = input().split()
  49. if not game_over:
  50. print(f'Pirate ship status: {sum(pirate_ship)}')
  51. print(f'Warship status: {sum(warship)}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement