﻿ Python Exercise: Find the median of three values - w3resource # Python Exercise: Find the median of three values

## Python Conditional: Exercise - 40 with Solution

Write a Python program to find the median of three values.

Pictorial Presentation: Sample Solution:

Python Code:

``````a = float(input("Input first number: "))
b = float(input("Input second number: "))
c = float(input("Input third number: "))
if a > b:
if a < c:
median = a
elif b > c:
median = b
else:
median = c
else:
if a > c:
median = a
elif b < c:
median = b
else:
median = c

print("The median is", median)
```
```

Sample Output:

```Input first number: 25
Input second number: 55
Input third number: 65
The median is 55.0
```

Flowchart : ## 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.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz

﻿

## Python: Tips of the Day

Python: Function With Multiple Outputs

If a function is required to return multiple values then:

```[Variable] AggregateFunction([Value] for [item] in [collection])
```