Perform selection sort by taking random numbers from 1 to 100.

Perform selection sort by taking random numbers from 1 to 100.

import random

def selection_sort(arr):
    """
    Sorts a list using the Selection Sort algorithm.
    """
    n = len(arr)
    # Traverse through all array elements
    for i in range(n):
        # Find the minimum element in the remaining unsorted array
        min_idx = i
        for j in range(i + 1, n):
            if arr[j] < arr[min_idx]:
                min_idx = j
        # Swap the found minimum element with the first element of the unsorted part
        arr[i], arr[min_idx] = arr[min_idx], arr[i]
    return arr

# --- Generate random numbers and sort them ---

# Generate 10 random numbers between 1 and 100
random_numbers = [random.randint(1, 100) for _ in range(10)]
print("Randomly generated numbers:", random_numbers)

# Sort the list using selection sort
sorted_numbers = selection_sort(random_numbers.copy())  # Using copy to keep original
print("Sorted numbers (Ascending):", sorted_numbers)

# Generate another set of 15 random numbers
random_numbers2 = [random.randint(1, 100) for _ in range(15)]
print("\nAnother set of random numbers:", random_numbers2)
sorted_numbers2 = selection_sort(random_numbers2.copy())
print("Sorted numbers (Ascending):", sorted_numbers2)