Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    Python Program to Find Largest of Three Numbers Using If

    Python Programming Examples


    This Python example code demonstrates a simple Python program to find the greatest of three numbers using If and print the output to the screen. The primary purpose of this Python program is to explain to beginners how decision-making statements work.

    Program:

    #Variable definition and assignment
    num1 = 25
    num2 = 30
    num3 = 20
    
    #Remove comments from the bottom lines to take input from the 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
    else:
       largest = num3
    
    #Print the output
    print("The largest number is", largest)

    Program Output:

    The largest number is 30


    Found This Page Useful? Share It!
    Get the Latest Tutorials and Updates
    Join us on Telegram

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.