Based on your question
What am I doing wrong here?
I'm going to take this line as a point of reference:
array.append(str(input(" ")))
>>> 0 10 20 30 40
print(array)
>>> ['0 10 20 30 40']
As you can see the output is of length 1. It only has one item which is a String.
You basically append the user input as a single string. Because you don't split the items in the input.
Solution
Input
0 10 20 30 40 50
1. This solution returns a list of Strings.
See solution 2 below for a list of int.
I just split the string based on your input in the question.
Also, notice my list comparison, I changed the comparison to int.
array = []
array=input(" ").split(" ")
for i in range(len(array)):
max_index = i
for j in range(i+1, len(array)):
if int(array[j]) > int(array[max_index]):
max_index = j
array[i],array[max_index] = array[max_index],array[i]
print(array)
Output
['50', '10', '20', '30', '40', '0']
['50', '40', '20', '30', '10', '0']
['50', '40', '30', '20', '10', '0']
['50', '40', '30', '20', '10', '0']
['50', '40', '30', '20', '10', '0']
['50', '40', '30', '20', '10', '0']
2. This solution returns a list of integers.
Here, I mapped the split input into the array.
array = []
array=list(map(int, input(" ").split(" ")))
for i in range(len(array)):
max_index = i
for j in range(i+1, len(array)):
if array[j] > array[max_index]:
max_index = j
array[i],array[max_index] = array[max_index],array[i]
print(array)
Output
[50, 10, 20, 30, 40, 0]
[50, 40, 20, 30, 10, 0]
[50, 40, 30, 20, 10, 0]
[50, 40, 30, 20, 10, 0]
[50, 40, 30, 20, 10, 0]
[50, 40, 30, 20, 10, 0]