Advertisement
bl00dt3ars

02. Array Modifier (Калоян Колев)

Jul 9th, 2021
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. def swap_elements(index_one, index_two, some_list):
  2.     result = some_list[index_one], some_list[index_two] = some_list[index_two], some_list[index_one]
  3.     return result
  4.  
  5.  
  6. def multiply_elements(first_index, second_index, some_list):
  7.     result = some_list[first_index] * some_list[second_index]
  8.     some_list[first_index] = result
  9.  
  10.  
  11. def decrease(some_list):
  12.     new_list = [el - 1 for el in some_list]
  13.     return new_list
  14.  
  15.  
  16. initial_array = [int(el) for el in input().split(" ")]
  17. command_data = input()
  18.  
  19. while not command_data == "end":
  20.     if command_data != "decrease":
  21.         command, index_one, index_two = command_data.split()
  22.         index_one = int(index_one)
  23.         index_two = int(index_two)
  24.         if command == "swap":
  25.             swap_elements(index_one, index_two, initial_array)
  26.         elif command == "multiply":
  27.             multiply_elements(index_one, index_two, initial_array)
  28.     else:
  29.         initial_array = decrease(initial_array)
  30.  
  31.     command_data = input()
  32.  
  33. print(", ".join([str(el) for el in initial_array]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement