Control Flow: The if, elif, else Statements

Sorting

Sort a list of 10 randomly generated numbers in increasing order of values

import random
 
list = []

for _ in range(10):
    number = random.randint(0, 100)
    list.append(number)
 
print (list) 
import random

list = []

for _ in range(10):
    number = random.randint(0, 100)
    list.append(number)

print(list)

for index in range(len(list)):
    for secondary_index in range(index + 1, len(list)):
        if (list[index] > list[secondary_index]):
            temp = list[index]
            list[index] = list[secondary_index]
            list[secondary_index] = temp

print(list)

Exercise: Find the index of the minimum and maximum number values in the initial list and the sorted list.

There are many sorting algorithms with different performance and complexity. An example list and implementations can be found at https://www.geeksforgeeks.org/sorting-algorithms/#algo and https://www.wikiwand.com/en/Sorting_algorithm