Guest User

Untitled

a guest
Jun 21st, 2020
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. pirates = list(map(int, input().split(">")))
  2. warship = list(map(int, input().split(">")))
  3. max_health = int(input())
  4. check = True
  5. win_check = False
  6.  
  7. while True:
  8. if win_check:
  9. break
  10.  
  11. commands = input()
  12.  
  13. if commands == "Retire":
  14. break
  15.  
  16. actions = commands.split(" ")
  17. if actions[0] == "Fire":
  18. index = int(actions[1])
  19. damage = int(actions[2])
  20.  
  21. if index in range(len(warship)):
  22. warship[index] -= damage
  23. if warship[index] <= 0:
  24. print("You won! The enemy ship has sunken.")
  25. check = False
  26. win_check = True
  27. break
  28.  
  29. elif actions[0] == "Defend":
  30. start_index = int(actions[1])
  31. end_index = int(actions[2])
  32. damage = int(actions[3])
  33.  
  34. if start_index not in range(len(pirates)) or end_index not in range(len(pirates)):
  35. continue
  36.  
  37. for j in range(start_index,end_index+1):
  38. pirates[j] -= damage
  39. if pirates[j] <= 0:
  40. print("You lost! The pirate ship has sunken.")
  41. check = False
  42. win_check = True
  43. break
  44.  
  45. elif actions[0] == "Repair":
  46. index = int(actions[1])
  47. health_gain = int(actions[2])
  48.  
  49. if index in range(len(pirates)):
  50. pirates[index] += health_gain
  51. if pirates[index] > max_health:
  52. pirates[index] = max_health
  53.  
  54. elif actions[0] == "Status":
  55. repairs_ships = 0
  56.  
  57. for k in range(len(pirates)):
  58. current_health = pirates[k]
  59. if current_health < max_health * 0.2:
  60. repairs_ships += 1
  61.  
  62. print(f"{repairs_ships} sections need repair.")
  63.  
  64. if check:
  65. print(f"Pirate ship status: {sum(pirates)}")
  66. print(f"Warship status: {sum(warship)}")
Add Comment
Please, Sign In to add comment