ads

A Function To Find The Largest Among Three Numbers



This code defines a function called largest that takes three numbers as input and returns the largest one using an if-elif statement. The function can be tested by calling it with some example inputs and printing the output..

 # function to find the largest among three numbers

def largest(num1, num2, num3):

    if (num1 >= num2) and (num1 >= num3):

        largest_num = num1

    elif (num2 >= num1) and (num2 >= num3):

        largest_num = num2

    else:

        largest_num = num3

    return largest_num


# test the function with some examples

print(largest(3, 4, 5))  # 5

print(largest(5, 4, 2))  # 5

print(largest(1, 1, 1) # 1


About Admin

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.

0 yorum :

Yorum Gönder