Python program to find largest of 3 numbers | Example code

  • by

You can make a program to find the largest of 3 numbers using proper logic of if elif and else block in Python. This is a conditional statement.


  1. Use an if-else statement, If (num1 > num2) and (num1 > num3), Print num1
  2. Else if (num2 > num1) and (num 2 > num3), Print num2
  3. Else, print num3
  4. End the program

Python program to find largest of 3 numbers example

Simple example code finds the largest number among the three input numbers.

def maximum(a, b, c):
    if (a >= b) and (a >= c):
        largest = a

    elif (b >= a) and (b >= c):
        largest = b
        largest = c

    return largest

res = maximum(2, 3, 1)

print("The largest number is", res)


Python program to find largest of 3 numbers

Use input numbers

Program to Find the Largest Among Three Numbers, where numbers are dynamically entered by the user.

# take three numbers from user
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))

if (num1 > num2) and (num1 > num3):
    largest = num1
elif (num2 > num1) and (num2 > num3):
    largest = num2
    largest = num3

print("The largest number is", largest)


Enter first number: 10
Enter second number: 50
Enter third number: 100
The largest number is 100.0

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. Required fields are marked *

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