Zed-King Institute

    Python Program to Find the Largest of Three Numbers

    easyif / elsePython

    A favourite practical question because it tests whether you can build a decision with more than two branches.

    The question

    Read three different integers (one per line) and print the largest of them. Use if/elif/else — do not use max().

    The code

    program.py

    a = int(input())
    b = int(input())
    c = int(input())
    if a > b and a > c:
        largest = a
    elif b > c:
        largest = b
    else:
        largest = c
    print("Largest =", largest)

    Input

    67
    19
    34

    Output

    Largest = 67

    How it works

    1. 1First check whether a is bigger than both b and c — the and operator needs both comparisons to be true.
    2. 2If a is not the largest, the answer must be b or c, so a single comparison b > c decides it.
    3. 3Store the winner in largest and print it once at the end.

    Common mistakes

    • Writing if a > b > c — it only proves a > b and b > c, and misses the case where c > b.
    • Using max() when the question says to use if-else — examiners take marks for that.

    Now solve a similar question yourself

    A new Python question every time, checked instantly.

    Practice questions

    More in if / else