Find Median Value
Take three numbers and print the median value (neither maximum nor minimum).
IntermediatePhase 1 - Level 4: Logical Operators & Compound StatementsExample 3 of 10
find-median-value.py
1# Take three numbers2a = float(input("Enter first number: "))3b = float(input("Enter second number: "))4c = float(input("Enter third number: "))56# Find median7if (a >= b and a <= c) or (a <= b and a >= c):8 median = a9elif (b >= a and b <= c) or (b <= a and b >= c):10 median = b11else:12 median = c1314print(f"Median: {median}")
Output
Enter first number: 10 Enter second number: 5 Enter third number: 15 Median: 10.0
What's going on
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
🔗Related Content
- 📖
Phase 1 - Learn Concepts
Review Phase 1 concepts and explanations
- 📝
Phase 1 - Quiz
Test your Phase 1 understanding with quiz questions
- 💻
Phase 1 - All Practice Problems
Explore all practice problems for Phase 1
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum