Advertisement
GeorgiLukanov87

moving_targets_functions

Jun 20th, 2022
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.60 KB | None | 0 0
  1. def is_index_valid(targets, index):
  2.     if 0 <= int(index) < len(targets):
  3.         return True
  4.     return False
  5.  
  6.  
  7. def shoot_function(targets, command):
  8.     action, index, power = command.split()
  9.     index = int(index)
  10.     power = int(power)
  11.     if is_index_valid(targets, index):
  12.         targets[index] -= power
  13.         if int(targets[index]) <= 0:
  14.             targets.remove(targets[index])
  15.     return targets
  16.  
  17. def add_function(targets, command):
  18.     action, index, value = command.split()
  19.     index = int(index)
  20.     value = int(value)
  21.     if is_index_valid(targets, index):
  22.         targets.insert(index, value)
  23.         return targets
  24.     print("Invalid placement!")
  25.  
  26.  
  27. def strike_function(targets, command):
  28.     action, index, radius = command.split()
  29.     index = int(index)
  30.     radius = int(radius)
  31.     left_side = targets[:index]
  32.     right_side = targets[index+1:]
  33.     if radius <= len(left_side) and radius <= len(right_side) and is_index_valid(targets,index):
  34.         for num in range(radius):
  35.             left_side.remove(left_side[-1])
  36.             right_side.pop(0)
  37.         targets.clear()
  38.         targets += left_side+right_side
  39.         return targets
  40.     else:
  41.         print('Strike missed!')
  42.  
  43.  
  44. targets = list(map(int, input().split()))
  45. command = input()
  46.  
  47. while not command == 'End':
  48.     if 'Shoot' in command:
  49.         shoot_function(targets, command)
  50.     elif 'Strike' in command:
  51.         strike_function(targets, command)
  52.     elif 'Add' in command:
  53.         add_function(targets, command)
  54.     command = input()
  55.  
  56. targets = ('|'.join(str(el) for el in targets))
  57. print(targets)
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement