Advertisement
ALEXANDAR_GEORGIEV

moving_target

Oct 23rd, 2022
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. def shoot(index, power, targets):
  2. if 0 <= index <= len(targets):
  3. if targets[index] - power <= 0:
  4. targets.pop(index)
  5. else:
  6. targets[index] -= power
  7. return targets
  8.  
  9. def add(index, value, targets):
  10. if 0 <= index < len(targets):
  11. targets.insert(index, value)
  12. else:
  13. print('Invalid placement!')
  14. return targets
  15.  
  16.  
  17. def strike(index, radius, targets):
  18. validator_index = index - radius >= 0 and index + radius < len(targets)
  19.  
  20. if validator_index:
  21. start_target_index = index - radius
  22. final_target_index = index + radius
  23. targets = [targets[i] for i in range(len(targets)) if i < start_target_index or i > final_target_index]
  24. else:
  25. print('Strike missed!')
  26.  
  27. return targets
  28.  
  29.  
  30. def moving_target_func(targets):
  31.  
  32. while True:
  33. command = input()
  34. if command == 'End':
  35. break
  36.  
  37. current_command, first_element, second_element = command.split(' ')
  38.  
  39. if current_command == 'Shoot':
  40. targets = shoot(first_element, second_element, targets)
  41.  
  42. elif current_command == 'Add':
  43. targets = add(first_element, second_element, targets)
  44.  
  45. elif current_command == 'Strike':
  46. targets = strike(first_element, second_element, targets)
  47.  
  48. result = '|'.join([str(num) for num in targets])
  49. print(result)
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. data = list(map(int, input().split(' ')))
  57. moving_target_func(data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement