Python program to find largest number in a list without max()

Here is a simple Python program that finds the largest number in a list without using the built-in max() function:

def find_largest(numbers):
    # Initialize largest to the first number
    largest = numbers[0]
    # Iterate through the numbers
    for num in numbers:
        # If a number is greater than largest
        if num > largest:
            # Update largest
            largest = num
    return largest

numbers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
print("The largest number in the list is:", find_largest(numbers))

This program defines a function find_largest() that takes in a list of numbers and finds the largest among them. The function initializes the variable largest to the first number and then iterates through the rest of the numbers, updating largest if a larger number is found. The function is called with a list of numbers as an argument and will return the largest number in the list.

Leave a Comment