How to get maximum of 3 numbers : Usage of if elif and else in Python.

Today we will look at a sample program or python script to get maximum number out of a set of numbers say 3.

Lets have a look at the program.


# Lets define a function max_num with 3 arguments.
# The function will return maximum number out of these three numbers.
def max_num(n1,n2,n3):
    if n1>=n2 and n1>=n3:
        return n1
    elif n2>=n1 and n2>=n3:
        return n2
        return n3



Lets run the program and see its output.

/Users/saket/PycharmProjects/1helloworld/venv/bin/python /Users/saketPycharmProjects/1helloworld/


Leave a Reply

Your email address will not be published.