Skip to main content
  • Python is available now. All other compilers are coming soon.

    Python
  • Popular Tutorials

    • Getting Started With Python
    • Python if Statement
    • while Loop in Python
    • Python Lists
    • Dictionaries in Python
    All Python Tutorials

    Reference Materials

    Built-in FunctionsList MethodsDictionary MethodsString Methods
    View all

Online Compilers

  • Python Compiler
  • Python Playground
  • Python Projects
  • Exercises

Tutorials

  • Learn Python
  • Python for Beginners
  • Variables and Types
  • Python Strings
  • Python Lists
  • Python If Else
  • Python For Loops
  • Python Functions
  • Python Classes

Examples

  • Python Examples
  • Hello World
  • Add Two Numbers
  • Even or Odd
  • Factorial
  • Fibonacci
  • Prime Check
  • Palindrome Check

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Use
  • Disclaimer

© 2026 ILoveCompiler. All rights reserved.

  1. Home
  2. Python Examples
  3. Find the Largest of Three Numbers

Conditional Statements · Python example

Find the Largest of Three Numbers

Combine conditions with and to find the maximum of three values.

Open the compilerAll examples
beginnerif elifcomparisonslogic

This example compares three values and selects the largest using if, elif, and else. It also works when values are equal.

example.py
a = 14
b = 27
c = 9

if a >= b and a >= c:
    largest = a
elif b >= a and b >= c:
    largest = b
else:
    largest = c

print(f"The largest number is {largest}")

How the code works

  • 14 >= 27 is False, so the first branch is skipped.
  • 27 >= 14 and 27 >= 9 are both True, so largest becomes 27.
  • The else branch is not executed.

Key ideas

  • and requires both conditions to be True.
  • elif is checked only when the previous condition was False.
  • The >= comparisons make ties select the first matching value.

Try changing it

  • Use the built-in max(a, b, c) and compare the result.
  • Read the three numbers from input.
  • Find the smallest number with the same structure.

Related examples

beginner

Even or Odd Checker

Use the modulo operator and an if-else statement to classify an integer.

beginner

Grade Calculator

Map a numeric score to a letter grade using an if-elif ladder.

Previous exampleEven or Odd CheckerNext exampleCheck a Leap Year

Expected output

The largest number is 27

Output is compared after trimming trailing whitespace on each line. Run the code to see it produced by CPython in your browser.

Practice next

Apply the same idea with automatic tests or browse a guided project.

ExercisesProjects