Skip to content

Python program to find largest of 2 numbers | Example code

  • by

To write a program to find the largest of 2 numbers use the if-else statement in Python, You have to compare two numbers using the if-else statement and will print the largest number.

Python program to find largest of 2 numbers example

Simple example code prints the greatest of two numbers using an if-else statement.

def maximum(a, b):
    if a >= b:
        return a
    else:
        return b


# Driver code
a = 0
b = 7
print("Largest number", maximum(a, b))

Output:

Python program to find largest of 2 numbers

Do comment if you have any doubts or suggestions on this Python program.

Note: IDE: PyCharm 2021.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.