Lab 9 – Python program that has a function to find the Max of three numbers
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))
Leave a reply