Advertisement
go6odn28

moving_targer_3

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