Python Practice › Function Programs › Program 4
Maximum of three numbers
Write a Python function to find the maximum of three numbers.
Input
17, 21, -9
Output
21
Approach
- Reuse a two-number max function twice.
Solution
def max_of_two(a, b): return a if a > b else b def max_of_three(a, b, c): return max_of_two(a, max_of_two(b, c)) print(max_of_three(17, 21, -9))Output
21
Line by line
Lines 4-5
Building on a smaller function keeps each one simple.
Learn the concept
New to this topic? Read the lesson, then come back.