Advertisement
GeorgiLukanov87

02. Array Modifier 100/100

Jun 24th, 2022
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. array = list(map(int, input().split()))
  2.  
  3. command = input()
  4. while not command == 'end':
  5.     if 'swap' in command:
  6.         command = command.split()
  7.         index1 = int(command[1])
  8.         index2 = int(command[2])
  9.         array[index1], array[index2] = array[index2], array[index1]
  10.  
  11.     elif 'multiply' in command:
  12.         command = command.split()
  13.         index1 = int(command[1])
  14.         index2 = int(command[2])
  15.         result = array[index1] * array[index2]
  16.         array[index1] = result
  17.     else:
  18.         for i in range(len(array)):
  19.             array[i] -= 1
  20.  
  21.     command = input()
  22.  
  23. print(', '.join(list(map(str,array))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement