Advertisement
Violeta1234

Untitled

Jun 23rd, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. list_pirate_ship = list(map(lambda x: int(x), input().split('>')))
  2. list_warship = list(map(lambda x: int(x), input().split('>')))
  3. max_health_capacity = int(input())
  4. line = input()
  5.  
  6.  
  7. def fire():
  8. index = int(tokens[1])
  9. ship_sinks = False
  10. if (len(list_warship) - 1) >= index >= 0:
  11. damage = int(tokens[2])
  12. list_warship[index] -= damage
  13. if list_warship[index] <= 0:
  14. ship_sinks = True
  15. return ship_sinks
  16.  
  17.  
  18.  
  19. def defend():
  20. start_index = int(tokens[1])
  21. end_index = int(tokens[2])
  22. damage = int(tokens[3])
  23. pirate_ship_sinks = False
  24. if (len(list_pirate_ship) - 1) >= start_index >= 0 and (len(list_pirate_ship) - 1) >= end_index >= 0:
  25. for index_d in range(start_index, end_index + 1):
  26. list_pirate_ship[index_d] -= damage
  27. if list_pirate_ship[index_d] <= 0:
  28. pirate_ship_sinks = True
  29. return pirate_ship_sinks
  30.  
  31.  
  32. def repair():
  33. index_r = int(tokens[1])
  34. health = int(tokens[2])
  35. if (len(list_warship) - 1) >= index_r >= 0:
  36. list_pirate_ship[index_r] += health
  37. if list_pirate_ship[index_r] > max_health_capacity:
  38. list_pirate_ship[index_r] = max_health_capacity
  39. return list_pirate_ship
  40.  
  41.  
  42. def status():
  43. sections_need_repair = []
  44. min_health = max_health_capacity * 0.2
  45. for index_s in range(len(list_pirate_ship)):
  46. if list_pirate_ship[index_s] < min_health:
  47. sections_need_repair.append(list_pirate_ship[index_s])
  48. return len(sections_need_repair)
  49.  
  50.  
  51. while True:
  52. tokens = line.split()
  53. command = tokens[0]
  54. if line == 'Retire':
  55. print(f'Pirate ship status: {sum(list_pirate_ship)}')
  56. print(f'Warship status: {sum(list_warship)}')
  57. break
  58. if command == 'Fire':
  59. fire()
  60. if fire():
  61. print('You won! The enemy ship has sunken.')
  62. break
  63. elif command == 'Defend':
  64. defend()
  65. if defend():
  66. print('You lost! The pirate ship has sunken.')
  67. break
  68. elif command == 'Repair':
  69. repair()
  70. elif command == 'Status':
  71. print(f'{status()} sections need repair.')
  72.  
  73. line = input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement