Write a functionthat takes unsorted list as a parameter and return a sorted listin decending order(Do notuse any built-in function)
def sort_list(numbers):
for i in range(len(numbers)):
for j in range(len(numbers)-i-1):
if numbers[j] < numbers[j+1]:
temp = numbers[j]
numbers[j] = numbers[j+1]
numbers[j+1] = temp
return numbers
numbers = [3,4,1,6,7,8,-2,0,5,4]
print("numbers: ", numbers)
sorted_numbers = sort_list(numbers)
print("sorted numbers: ", sorted_numbers)
Comments
Leave a comment