Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Lab 9 – Python program that has a function to find the Max of three numbers

Lab 9

Write a Python program that has a function to find the Max of three numbers. Obtain the numbers from the user.

10 points for a correct working program?

Answer:


##function definition
def maximum(a, b, c):

    ##check if a is the largest
    if (a >= b) and (a >= c):
        largestNumber = a

    ##check if b is the largest
    elif (b >= a) and (b >= c):
        largestNumber = b

    ##therefore c is the largest number
    else:
         largestNumber = c

    return largestNumber

## Accept input from the user (integer)
a = float(input("Enter the first number: "))
b = float(input("Enter the second number: "))
c = float(input("Enter the third number: "))

## Display the result
print("The maximumum number is: ",maximum(a, b, c))

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!