Python Biggest of Three Numbers Program

Beginner
5 min read
Updated: Oct 2026
3 programs
Live preview

What Is the Biggest of Three Numbers?

Given three values a, b, and c, the biggest is the one that is greater than or equal to both of the others.

Remember
Example: a = 14, b = 7, c = 22
  22 >= 14 and 22 >= 7  → biggest is 22

Ties: a = 10, b = 10, c = 3
  either 10 is a valid maximum
abcBiggest
1472222
1010310
-5-2-9-2
5555

How to Find the Biggest of Three Numbers in Python

Compare pairwise (or call max) and prefer >= so ties stay correct.

  1. If a >= b and a >= c, return a.
  2. Else if b >= a and b >= c, return b.
  3. Otherwise return c.
  4. Shortcut: max(a, b, c).
MethodIdeaTimeBest for
If-elif ladderExplicit >= checksO(1)Interviews, default
maxmax(a, b, c)O(1)Short production code
Nested maxmax(a, max(b, c))O(1)Teaching pairwise max

Pseudocode

Pseudocode
function Biggest(a, b, c):
    if a >= b and a >= c:
        return a
    if b >= a and b >= c:
        return b
    return c

Cheat Sheet

Keep these patterns handy while coding.

TopicDetail
a winsa >= b and a >= c
b winsb >= a and b >= c
elsereturn c
One-linermax(a, b, c)
Many valuesUse a running-max loop (see Maximum of Array)

Live Preview

Enter three numbers to see which is biggest.

Integers and decimals both work. Tap a chip or type your own values.

Result
a = 14, b = 7, c = 22
biggest = 22

Worked Walkthrough — 14, 7, 22

Apply the if-elif ladder step by step.

Calculation
a = 14, b = 7, c = 22

Is a >= b and a >= c?
  14 >= 7  → true
  14 >= 22 → false
  → a is not the biggest

Is b >= a and b >= c?
  7 >= 14  → false
  → b is not the biggest

Otherwise return c
  biggest = 22

Python Programs

Start with an if-elif ladder, then use built-in max, and finish with nested pairwise max.

Example 1 — If-Elif Ladder

Explicit comparisons with >= — the interview default.

Python
def find_biggest(num1, num2, num3):
    if num1 >= num2 and num1 >= num3:
        return num1
    elif num2 >= num1 and num2 >= num3:
        return num2
    return num3


number1 = 14
number2 = 7
number3 = 22
result = find_biggest(number1, number2, number3)
print(f"The biggest number is: {result}")

How It Works

  1. If num1 is at least as large as the other two, return it.
  2. Else if num2 wins both comparisons, return num2.
  3. Otherwise num3 must be the maximum.
  4. >= keeps ties correct (equal largest values still return a valid max).
  5. Sample 14, 7, 22 prints 22.

Example 2 — Built-in max

Short and idiomatic — Python max accepts any number of arguments.

Python
def find_biggest_with_max(a, b, c):
    return max(a, b, c)


a = 14
b = 7
c = 22
print(f"The biggest number is: {find_biggest_with_max(a, b, c)}")

How It Works

  1. max returns the largest of its arguments.
  2. Pass all three values in one call: max(a, b, c).
  3. Same answer as the if-elif ladder — fewer lines.
  4. Still explain the ladder in interviews before relying on the built-in.
  5. 14, 7, 22 → 22.

Example 3 — Nested max

Pairwise nesting — useful when teaching two-argument max.

Python
def find_biggest_nested(a, b, c):
    return max(a, max(b, c))


print(find_biggest_nested(5, 5, 3))
print(find_biggest_nested(-1, -4, -2))

How It Works

  1. Inner max(b, c) picks the larger of the last pair.
  2. Outer max(a, …) compares that result with a.
  3. Ties: 5 vs 5 vs 3 → 5.
  4. Negatives: −1 vs −4 vs −2 → −1.
  5. Equivalent to max(a, b, c) for three values.

Edge Cases & Pitfalls

Check these before calling the solution done.

Ties

Prefer >= over >

Equal largest values still return a valid maximum with >=.

Negatives

Largest can still be negative

Among −5, −2, −9 the biggest is −2 — do not assume a positive answer.

N values

Do not nest forever

For many numbers, use a running-max loop instead of nested ifs.

Types

Compare like with like

Mixing incompatible types can raise TypeError. Keep inputs numeric.

Time and Space Complexity

ProgramTimeExtra space
If-elif / max / nestedO(1)O(1)
Running max over N valuesO(N)O(1)

Three fixed inputs need only a few comparisons — constant time and space.

Key Takeaways

  • Rule: return the value that is >= both others.
  • Ties: use >= so equal maxima still work.
  • Shortcut: max(a, b, c).
  • Test: 14, 7, 22 → 22; −5, −2, −9 → −2.

One line: compare three values; return the one that is not smaller than the other two.

Frequently Asked Questions

Compare with if-elif using >=, or call max(a, b, c). Both return the largest value.
>= handles ties. If two values share the maximum, one valid answer is still returned.
Yes. Python’s max accepts any number of arguments, so max(a, b, c) works directly. In interviews, write the if-elif version first to show the logic.
For exactly three numbers, time is O(1) and extra space is O(1).
Yes. Comparisons treat negatives the same way — among −5, −2, −9 the biggest is −2.

Next: Binary to Decimal

Convert a binary string into its decimal integer value.

Binary to decimal tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful