zaxooooo

Fundamentals module Task 3

Feb 25th, 2021
812
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def check_if_index_is_valid(index, len_list):
  2.     if index in range(len_list):
  3.         return True
  4.     return False
  5.  
  6.  
  7. targets = [int(el) for el in input().split()]
  8.  
  9. command_data = input()
  10.  
  11. while not command_data == "End":
  12.     command, index, val = command_data.split()
  13.     index = int(index)
  14.     val = int(val)
  15.     if command == "Shoot":
  16.         if check_if_index_is_valid(index, len(targets)):
  17.             targets[index] -= val
  18.             if targets[index] <= 0:
  19.                 targets.pop(index)
  20.     elif command == "Add":
  21.         if check_if_index_is_valid(index, len(targets)):
  22.             targets.insert(index, val)
  23.         else:
  24.             print("Invalid placement!")
  25.     elif command == "Strike":
  26.         left_most_index = index - val
  27.         right_most_index = index + val
  28.         if check_if_index_is_valid(index, len(targets)) and check_if_index_is_valid(left_most_index, len(targets)) and check_if_index_is_valid(right_most_index, len(targets)):
  29.             left_unstriked_part = targets[:left_most_index]
  30.             right_unstriked_part = targets[right_most_index+1:]
  31.             targets = left_unstriked_part + right_unstriked_part
  32.         else:
  33.             print("Strike missed!")
  34.  
  35.     command_data = input()
  36.  
  37.  
  38. print('|'.join([str(el) for el in targets]))
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×