Advertisement
Kaloyankerr

Array Modifier

Jul 8th, 2020
1,921
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. array = input().split()
  2. command = input().split()
  3. amount = 0
  4. # new_array = []
  5.  
  6. while not command == "end":
  7.     if command[0] == "swap":
  8.         array[int(command[1])], array[int(command[2])] = array[int(command[2])], array[int(command[1])]
  9.     elif command[0] == "multiply":
  10.         amount = int(array[int(command[1])]) * int(array[int(command[2])])
  11.         array.remove(array[int(command[1])])
  12.         array.insert(int(command[1]), str(amount))
  13.     elif command[0] == "decrease":
  14.         array = list(map((lambda x: x -1), array))
  15.         # for item in array:
  16.         #     new_array.append(int(item) - 1)
  17.     command = input().split()
  18.     if command[0] == "end":
  19.         break
  20.  
  21. print(", ".join(map(str, array)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement