Find Biggest of Three Numbers in Python

Beginner
⏱️ 9 min read
📚 Updated: Aug 2026
🎯 3 Code Examples
🚀 Live Preview
Conditionals

What You’ll Learn

Finding the biggest of three numbers is a classic conditional warm-up. This tutorial covers the comparison rule, a live preview, algorithm steps, worked Python examples, edge cases, and complexity.

Goal

Largest of a, b, c

Return the value that is not smaller than the other two.

If-Elif Ladder

Explicit logic

Compare with >= so ties still pick a valid maximum.

Built-in max

max(a, b, c)

Short and clear for real code; still explain the ladder in interviews.

Ties & Negatives

Edge cases

Equal largest values and all-negative inputs still work the same way.

Live Preview

Try a, b, c

Enter three numbers and see the maximum instantly in the browser.

O(1)

Complexity

A fixed number of comparisons — constant time and constant extra space.

Introduction

Given three numbers a, b, and c, the task is to find the biggest value — the one that is greater than or equal to both of the others.

You can write an explicit if-elif-else ladder, nest max calls, or use Python’s built-in max(a, b, c). If two or three values tie for largest, returning any one of those tied values is valid.

Why it matters?

It trains clear branching, tie handling, and the habit of explaining O(1) complexity for fixed-size inputs.

Key Highlights

Prefer >=

Handles equal largest values without special cases.

Negatives OK

Among negatives, the largest is the least negative.

Two Styles

Write the ladder for interviews; use max in apps.

Constant Cost

Three fixed inputs need only a few comparisons.

In short: compare a, b, and c; return the value that is greater than or equal to the other two.

📝 Problem & Approach

Given three numbers a, b, and c, return the maximum among them.

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

Inputs & Outputs

ItemTypeDescription
a, b, cint / floatThree numbers to compare (ints or floats both work).
Return / printsame typeThe largest value among the three (any tied max is fine).

Minimal workflow

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

Method comparison

MethodIdeaNotes
If-elif ladderExplicit comparisons with >=Best for showing interview logic
Built-in maxmax(a, b, c)Shortest production style

⚡ Quick Reference

GoalPattern
a is biggesta >= b and a >= c
b is biggestb >= a and b >= c
Otherwisereturn c
One-linermax(a, b, c)
Nested maxmax(a, max(b, c))
Many valuesmax(values) or a running-max loop

📋 If-Elif vs max() vs Nested max

Same answer — different clarity and interview signaling.

If-elif
compare >=

Shows branching clearly; preferred whiteboard style

max(a, b, c)
built-in

Idiomatic Python for real applications

Nested max
max(a, max(b, c))

Same idea; useful when teaching pairwise max

Interview tip
ladder first

Write if-elif, then mention max as a shortcut

Context

When This Problem Shows Up

Reach for biggest-of-three drills when branching and comparisons matter.

  1. Interview warm-ups

    Quick check of if-elif structure and tie handling.

  2. Teaching conditionals

    First multi-branch program after simple if/else.

  3. Gateway to N-max

    Natural step toward a running-max loop over a list.

  4. Small fixed comparisons

    UI scores, three sensors, or three candidate prices.

  5. Not for huge lists alone

    For many values, use a loop or max(iterable) instead of nested ifs.

Key benefit: one tiny problem that covers branching, ties, negatives, and O(1) complexity talk.

🔮 Live Preview

Enter three numbers and check the biggest value instantly.

Integers and decimals both work.

Live result
Press "Run" to see the biggest value.

Examples Gallery

Three complete Python programs — if-elif ladder, built-in max, and nested max. Click View Output to reveal sample console results.

📚 Getting Started

Explicit comparisons — the interview default.

Example 1 — If-Elif-Else Approach

Check a, then b, otherwise return c — using >= for ties.

python
def find_biggest(num1: int, num2: int, num3: int) -> int:
    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

The first branch wins when num1 is a maximum. The second branch covers when num2 is a maximum. Otherwise num3 must be biggest.

⚡ Idiomatic Python

Same answer with the built-in helper.

Example 2 — Built-in max()

Pass all three arguments directly to max.

python
def find_biggest_with_max(a: int, b: int, c: int) -> int:
    return max(a, b, c)


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

How It Works

max compares its arguments and returns the largest. Great for production code after you have already explained the comparison logic.

🔁 Pairwise Style

Build the three-way max from two-way max calls.

Example 3 — Nested max

First take the larger of b and c, then compare with a.

python
def find_biggest_nested(a: int, b: int, c: int) -> int:
    return max(a, max(b, c))


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

How It Works

max(b, c) reduces two values to one candidate; then max(a, …) finishes the job. The tie case 5,5,3 returns 5; the all-negative case returns -1.

🧠 How the Algorithm Decides

1

Test a

If a >= b and a >= c, a is a maximum — return it.

Branch
2

Test b

Otherwise, if b >= a and b >= c, return b.

Branch
3

Else c

If the first two checks fail, c must be the biggest.

Fallback
=

Maximum found

Return that value — ties are already handled by >=.

🔎 Worked Walkthrough — 14, 7, 22

Trace the if-elif ladder with a = 14, b = 7, c = 22.

CheckConditionResult
a biggest?14 >= 7 and 14 >= 22False (14 < 22)
b biggest?7 >= 14 and 7 >= 22False
Fallbackreturn c22

Tie example: for 5, 5, 3, the first branch 5 >= 5 and 5 >= 3 is true, so the answer is 5.

Use Cases

Where biggest-of-three checks show up beyond the interview prompt.

1. Interview Warm-Ups

Tests if-elif structure and clear return values.

Example: write find_biggest(a, b, c).

2. Teaching Branches

Makes multi-way decisions feel concrete.

Example: chalkboard walkthrough of 14, 7, 22.

3. Small Scoreboards

Pick the best of three fixed candidates.

Example: three quiz attempts.

4. Gateway to N-Max

Leads into running-max loops over lists.

Example: max of an array.

5. Complexity Practice

Argue O(1) time for a fixed three inputs.

Example: “how many comparisons?”

6. Tie Talk

Shows why >= is safer than strict >.

Example: inputs 5, 5, 3.

Pro Tip: keep a pure find_biggest helper and print outside it — easier to test ties and negatives.

Advantages

Why this pattern works well in interviews and classwork.

  1. 1. Tiny and Clear

    A few comparisons map directly to the definition of maximum.

  2. 2. Constant Cost

    Fixed three inputs mean O(1) time and O(1) extra space.

  3. 3. Easy Built-in Shortcut

    max(a, b, c) keeps application code short after you know the logic.

  4. 4. Natural Edge-Case Story

    Ties and negatives give interviewers clear follow-up questions.

Pro Tip: say “return any tied maximum” before coding — it justifies >= immediately.

Usage Tips

Small habits that keep biggest-of-three code interview-ready.

  1. 1. Use >= for Ties

    Strict > can skip equal largest values depending on branch order.

  2. 2. Lead with the Ladder

    Write if-elif first in interviews, then mention max.

  3. 3. Spot-Check Negatives

    Assert max(-1, -4, -2) == -1 before calling it done.

  4. 4. Keep the Helper Pure

    Return the value; print outside the function.

  5. 5. Scale Carefully

    For many numbers, switch to a loop or max(iterable).

Pro Tip: dry-run both a clear winner (14, 7, 22) and a tie (5, 5, 3) on paper once.

Common Pitfalls

Mistakes that commonly break biggest-of-three solutions.

  1. 1. Using Strict > Carelessly

    Tie cases may fall through branches unexpectedly depending on order.

    → Prefer >= when any tied maximum is acceptable.

  2. 2. Assuming Negatives Are Invalid

    Maximum among negatives is still well-defined.

    → Test an all-negative triple.

  3. 3. Comparing Strings by Accident

    Input read as text compares lexicographically, not numerically.

    → Convert with int / float before comparing.

  4. 4. Only Calling Built-in max in Interviews

    Interviewers often want to see the comparison logic.

    → Write the ladder, then mention max as a shortcut.

  5. 5. Exploding Ifs for N Values

    Nested conditions do not scale past three inputs.

    → Use a running maximum when N grows.

Edge Cases

Check these inputs before calling the solution done.

Ties

Equal largest values

For 5, 5, 3, the answer is still 5.

All equal

Any value works

For 2, 2, 2, return 2.

Negatives

All values negative

The greatest value is the least negative number.

Zeros

Mix with negatives

0, -1, -5 → 0.

Floats

Same idea

Comparisons work for floats; adjust type hints if needed.

Input type

Parse before compare

Do not compare string digits as text.

⚖️ Facts Worth Knowing

Handy follow-ups interviewers sometimes ask.

  • Associative. max(a, max(b, c)) equals max(max(a, b), c).
  • Idempotent. max(x, x) = x, which is why ties are easy.
  • Dual problem. Biggest of three mirrors smallest of three with min / <=.
  • Fixed size. Complexity stays O(1) only while the input count is fixed at three.

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Verify classics

  • 14, 7, 22 → 22
  • 5, 5, 3 → 5
  • -1, -4, -2 → -1

2. Write smallest of three

  • Mirror the ladder with <=
  • Or use min(a, b, c)

3. Extend to a list

  • Running max over N values
  • State O(N) time

4. Implement both styles

  • If-elif and max
  • Assert they agree on a test set

Notes

  • Definition. Biggest means greater than or equal to each of the other two.
  • Use >= so equal largest values still return correctly.
  • In interviews, show the ladder first; mention max(a, b, c) second.
  • State O(1) time and O(1) extra space for exactly three inputs.

Quick Takeaway: compare a, b, and c with a few >= checks (or max) and return the largest.

⏱️ Time and Space Complexity

ProgramTimeExtra space
If-elif checks for 3 numbersO(1)O(1)
Built-in max(a, b, c)O(1)O(1)
Nested max(a, max(b, c))O(1)O(1)
Wrap Up

🎉 Conclusion

Finding the biggest of three numbers is a clean branching exercise: compare with >=, handle ties, and return the winner. Master the if-elif ladder first, then use max(a, b, c) when brevity matters.

Practice the three examples above, then continue to binary-to-decimal for a classic base-conversion warm-up.

Prefer >= for ties, test negatives, and state O(1) time for exactly three inputs.

💡 Best Practices

✅ Do

  • Compare with >= for clear ties
  • Show the if-elif ladder in interviews
  • Test ties and all-negative inputs
  • Mention max(a, b, c) as a shortcut
  • State O(1) time and space

❌ Don’t

  • Rely only on max when logic must be shown
  • Compare unparsed strings as numbers
  • Assume negatives are invalid
  • Nest ifs endlessly for long lists
  • Forget that any tied maximum is valid

Key Takeaways

Knowledge Unlocked

Five things to remember about biggest of three

Pick the maximum the interview-friendly way.

5
Core concepts
if 02

Ladder

if / elif / else

Code
M 03

max()

Built-in shortcut

Code
= 04

Ties

Any max is OK

Edge
O 05

Complexity

O(1) time

Analysis

❓ Frequently Asked Questions

You compare the values using if-elif conditions, or use max(a, b, c). Both return the largest value.
Using >= handles ties clearly. If two numbers are equal and largest, one valid maximum is still returned correctly.
Yes. You can directly use max(a, b, c). In interviews, writing the if-elif version first helps show your logic.
For exactly three numbers, time complexity is O(1) and extra space is O(1).
Yes. Comparisons work the same way for negative values too.
Use a loop with a running maximum, or max() on a list/array of values.
Any of them is a valid answer — they all share the same maximum value.
Yes. It is equivalent and still O(1) for three fixed arguments.

Did you Know? 🔊

To find the biggest of 3 values, you only need a few comparisons, so the solution runs in O(1) time and O(1) space.

Continue to Binary to Decimal

Learn how to convert a binary number into its decimal equivalent in Python.

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.

9 people found this page helpful