Вот код.Я сделал как можно меньше изменений, чтобы вам было легче это понять.Просто скопируйте-сохраните-запустите этот код как он есть:
def Sorting_a_List(input_list):
for k in range(0,len(input_list)):
for a in range(0,len(input_list)-1):
if input_list[k]>input_list[a]:
continue
else:
b=input_list[k]
input_list[k]=input_list[a]
input_list[a]=b
return input_list
# If you just need the function, then skip copying the lines below!
input_list = input("Enter the list separated by space: ").split()
input_list = list(map(int,input_list))
print("Your list in Ascending order:",Sorting_a_List(input_list))
Код выше (на основе вашего кода) кажется довольно занятым, поэтому ниже приведена просто более понятная версия с использованием сортировки по пузырькам:
def bubble_sort(inputList):
index = len(inputList) - 1
while index >= 0:
for j in range(index):
if inputList[j] > inputList[j+1]:
inputList[j], inputList[j+1] = inputList[j+1], inputList[j]
index -= 1
return inputList
# If you just need the function, then skip copying the lines below!
inputList = input("Enter the list separated by space: ").split()
inputList = list(map(int,inputList))
print("Your list in Ascending order:",bubble_sort(inputList))
Надеюсь, это поможет!