Skip to main content

Command Palette

Search for a command to run...

Write a Program to Find the Largest of Three Numbers in Python – Step-by-Step Example

Published
2 min read

Learning to write a program to find the largest of three numbers in Python is one of the most common beginner exercises. It helps new programmers understand how comparison and conditional statements work together to produce meaningful results.

The idea is simple — take three numbers as input and compare them to determine which one is the largest. Python’s if, elif, and else statements make it easy to perform these comparisons in a clear and structured way.

Here’s how the logic works step by step:

  1. Accept three numbers from the user.

  2. Compare the first number with the other two.

  3. If the first number is greater than both, it is the largest.

  4. Otherwise, compare the second number with the third.

  5. The greater number among the remaining two is the largest.

For example, if the numbers entered are 15, 22, and 19, the output will be:
“The largest number is 22.”

This basic exercise helps learners understand the importance of conditional branching and logical comparisons in programming. It also prepares them to handle more complex problems where multiple conditions must be checked.

An alternate and shorter way to solve this is by using Python’s built-in max() function, which directly returns the largest value among multiple inputs.

To see a complete example with code and explanation, visit:
https://docs.vultr.com/python/examples/find-the-largest-among-three-numbers

This tutorial shows exactly how to write a program to find the largest of three numbers in Python with clear and beginner-friendly logic.