Smallest Element in List

Find the smallest element in a list of numbers.

PythonBeginner
Python
# Program to find smallest element in a list

numbers = list(map(float, input("Enter numbers separated by space: ").split()))

if not numbers:
    print("List is empty.")
else:
    print("Smallest element:", min(numbers))

Output

Enter numbers separated by space: 3 7 2 9
Smallest element: 2.0

We use the built-in min() to obtain the smallest value, again checking for an empty list.