Advertisement
go6odn28

moving_target...

Feb 27th, 2024
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. def validation(numbers_sequence):
  2.     return 0 <= index < len(numbers_sequence)
  3.  
  4.  
  5. def action_shoot(numbers_sequence):
  6.     if validation(numbers_sequence):
  7.         numbers_sequence[index] -= value
  8.         if numbers_sequence[index] <= 0:
  9.             numbers_sequence.pop(index)
  10.     return numbers_sequence
  11.  
  12.  
  13. def action_add(numbers_sequence):
  14.     if validation(numbers_sequence):
  15.         numbers_sequence.insert(index, value)
  16.     else:
  17.         print('Invalid placement!')
  18.     return numbers_sequence
  19.  
  20.  
  21. def action_strike(numbers_sequence):
  22.     if validation(numbers_sequence):
  23.         if 0 <= index - value < len(numbers_sequence) and 0 <= index + value <(len(numbers_sequence)):
  24.             list1 = numbers_sequence[:index - value]
  25.             list2 = numbers_sequence[index + value + 1:]
  26.             numbers_sequence = list1 + list2
  27.         else:
  28.             print('Strike missed!')
  29.     return numbers_sequence
  30.  
  31.  
  32. def main_func(targets):
  33.     action = command[0]
  34.     if action == 'Shoot':
  35.         action_shoot(targets)
  36.     elif action == 'Add':
  37.         action_add(targets)
  38.     elif action == 'Strike':
  39.         targets = action_strike(targets)
  40.     return targets
  41.  
  42.  
  43. targets_sequence = list(map(int, input().split()))
  44.  
  45. while True:
  46.     command = input().split()
  47.     if command[0] == 'End':
  48.         result = '|'.join(map(str, targets_sequence))
  49.         print(result)
  50.         break
  51.  
  52.     index, value = int(command[1]), int(command[2])
  53.     targets_sequence = main_func(targets_sequence)
  54.  
  55.  
  56.  
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement