Advertisement
go6odn28

array_modifiyer

Feb 14th, 2024
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. def swap(array_values_, idx1, idx2):
  2.     array_values_[idx1], array_values_[idx2] = array_values_[idx2], array_values_[idx1]
  3.     return array_values_
  4.  
  5.  
  6. def multiply(array_values_, idx1, idx2):
  7.     array_values_[idx1] *= array_values_[idx2]
  8.     return array_values_
  9.  
  10.  
  11. def decrease(array_values_):
  12.     array_values_ = [n - 1 for n in array_values_]
  13.     return array_values_
  14.  
  15.  
  16. def array_modifier():
  17.     array_values = [int(x) for x in input().split()]
  18.     while True:
  19.         command = input()
  20.         if command == 'end':
  21.             break
  22.  
  23.         data = command.split()
  24.         current_command = data[0]
  25.  
  26.         if current_command == "swap":
  27.             index1, index2 = int(data[1]), int(data[2])
  28.             array_values = swap(array_values, index1, index2)
  29.  
  30.         elif current_command == "multiply":
  31.             index1, index2 = int(data[1]), int(data[2])
  32.             array_values = multiply(array_values, index1, index2)
  33.  
  34.         elif current_command == "decrease":
  35.             array_values = decrease(array_values)
  36.  
  37.     print(", ".join(map(str, array_values)))
  38.  
  39.  
  40. array_modifier()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement