n = int(input('Total number of items in list: ')) L = [] # Input items into the list for i in range(n): item = int(input('Enter the item: ')) L.append(item) # Selection sort algorithm for i in range(n - 1): min_index = i for j in range(i + 1, n): if L[j] < L[min_index]: min_index = j L[i], L[min_index] = L[min_index], L[i] # Print the sorted list print('Sorted list:\n', L)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter