Largest of Three Numbers

Easy ⏱ 8 min 79% acceptance ★★★★☆ 4.3
Write a function largest_of_three(a, b, c) that returns the largest of the three given numbers using only if/elif/else comparisons (no built-in max).

Examples

Example 1
Input
largest_of_three(3, 9, 5)
Output
9
Explanation

9 is greater than both 3 and 5.

Example 2
Input
largest_of_three(7, 7, 2)
Output
7
Explanation

Ties resolve to the tied value.

Constraints

  • a, b, c are numbers.
  • Do not use the built-in max() function.

Topics

Conditional Statementsnested conditionals

Companies

FlipkartHCLTech

Hints

Hint 1

Compare a and b first, keep the winner, then compare against c.

Hint 2

Chained comparisons like `a >= b and a >= c` also work.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.