Write Python. Understand every error.

Open the editor

Python programs · Basics

Python program to find the largest of three numbers

Finding the largest of three numbers practises comparisons and the word and.

Approach

  1. Read three whole numbers from one line.
  2. If the first is at least as large as both others, it wins.
  3. Otherwise compare the second and the third.

The program

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

Sample run

Input
12 45 7
Output
Largest: 45

Run this program in Py-CRAFT

How the code works

The first test asks whether a beats both others. If not, the winner must be b or c, so one more comparison decides. Using >= makes sure equal numbers are handled. Python's built-in max(a, b, c) does the same in one call, but writing the comparisons yourself shows how decisions work.

Try changing it

Common mistakes

Learn the ideas

More programs

Share this page: