Logic Building
# Take three numbers
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
c = float(input("Enter third number: "))
# Find median
if (a >= b and a <= c) or (a <= b and a >= c):
median = a
elif (b >= a and b <= c) or (b <= a and b >= c):
median = b
else:
median = c
print(f"Median: {median}")Output
Enter first number: 10 Enter second number: 5 Enter third number: 15 Median: 10.0
Median is the middle value when sorted.
Key Concepts:
- Check if a number is between the other two
- Median is neither max nor min
- Use OR to check both orderings