Cody Bable

Generation

generate functionSun, 02 Jul 2023

store largest to smallest numbers in a list and print all the numbers in the list

def sort_largest_to_smallest(lst): for i in range(len(lst)): for j in range(len(lst)-i-1): if lst[j] > lst[j+1]: lst[j], lst[j+1] = lst[j+1], lst[j] return lst lst = [2, 5, 7, 10, 3, 4, 1] print(sort_largest_to_smallest(lst))

Questions about programming?Chat with your personal AI assistant