How to swap min and max?

print(“Enter a list of numbers separated by spaces:”)
list = [int(s) for s in input().split()]

your code goes here.

max = list[0]
for i in range(1, len(list)):
if list[i] > max:
max = list[i]
Location1 = list.index(max)

min = list[0]
for i in range(1, len(list)):
if list[i] < min:
min = list[i]
Location2 = list.index(min)

tmp = list(max)
list(max) = list(min)
list(min) = tmp

for x in range(len(list)):
print(list, end=" ")

I’ll put 3 4 5 1 2 and the output will be 3 4 1 2 5. However, I couldn’t reach to the output. Help meee!

Presumably, you intended to assign list = [3 4 5 1 2] after using the input().split()
For swapping, you can use code like this:

a = 5
b = 6
print(a, b) # just so you can see the values
a, b = b, a
print(a, b) # again to see the values

It will help you to trace your code. For example, you start with max = 3.
Then you see that list[1] equals 4 which is greater than 3, so you assign 4 to max.
Location1 = 1
If you work through this loop to see the result, you’ll find a similar pattern for the “min” loop and Location2.