Write a program to calculate the minimum element of a given list of numbers.

 

def find_minimum(numbers):
    if len(numbers) == 0:
        return None
    minimum = numbers[0]
    for num in numbers:
        if num < minimum:
            minimum = num
    return minimum

# Example usage
my_list = [5, 2, 8, 1, 6, 3]
min_value = find_minimum(my_list)
print("Minimum value:", min_value)

 

In this program, the find_minimum() function takes a list of numbers as input. It initializes the minimum variable with the first element of the list. Then, it iterates over each element in the list and compares it with the current minimum value. If a smaller value is found, it updates the minimum value. Finally, it returns the minimum value found in the list.

In the example usage, the program calculates the minimum value of the my_list list and prints it to the console. You can modify the my_list variable to contain different numbers to find the minimum value of a different list.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *