Largest Element in List

Find the largest element in a list of numbers.

PythonBeginner
Python
# Program to find largest element in a list

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

if not numbers:
    print("List is empty.")
else:
    print("Largest element:", max(numbers))

Output

Enter numbers separated by space: 3 7 2 9
Largest element: 9.0

We use the built-in max() to obtain the largest value, with an empty-list check.