In this python function program, we will find the maximum of three numbers.
What is Function?
It is a block of code that executes when it is called.
To create a function use def keyword.
Steps to solve the program
- Create a function largest
- Use the def keyword to define the function.
- Pass three parameters i.e. numbers to the function.
- Take 3 numbers as input through the user and pass them to the function while calling the function.
- Find the largest number among three numbers using logic and if-else statements.
def largest(a,b,c):
if a>b:
if a>c:
print(f"{a} is the greatest number")
elif b>a:
if b>c:
print(f"{b} is the greatest number")
else:
print(f"{c} is the greatest number")
num1 = int(input("Enter number 1: "))
num2 = int(input("Enter number 2: "))
num3 = int(input("Enter number 3: "))
largest(num1,num2,num3)
Output :
Enter number 1: 50
Enter number 2: 60
Enter number 3: 44
60 is the greatest number