w3resource
Python Exercises

Python Exercise: Find the Max of three numbers

Python Functions: Exercise-1 with Solution

Write a Python function to find the Max of three numbers.

Sample Solution:-

Python Code:

def max_of_two( x, y ):
    if x > y:
        return x
    return y
def max_of_three( x, y, z ):
    return max_of_two( x, max_of_two( y, z ) )
print(max_of_three(3, 6, -5))

Sample Output:

6  

Pictorial presentation:

Python exercises: Find the Max of three numbers.

Flowchart:

Flowchart: Python exercises: Find the Max of three numbers.

Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Python-Functions-Exercises Home.
Next: Write a Python function to sum all the numbers in a list.

What is the difficulty level of this exercise?