Take Three Numbers and Print the Largest
Compare three numbers and find the largest.
BeginnerPhase 1 - Level 1: Simple ConditionsExample 7 of 10
take-three-numbers-and-print-the-largest.py
1# Take three numbers as input2num1 = float(input("Enter first number: "))3num2 = float(input("Enter second number: "))4num3 = float(input("Enter third number: "))56# Find largest number7if num1 >= num2 and num1 >= num3:8 largest = num19elif num2 >= num1 and num2 >= num3:10 largest = num211else:12 largest = num31314print(f"Largest number: {largest}")
Output
Enter first number: 10 Enter second number: 25 Enter third number: 15 Largest number: 25.0
What's going on
Compare three numbers by checking each one against the other two.
Key Concepts:
Check if num1 is >= both num2 and num3
Else check if num2 is >= both num1 and num3
Otherwise num3 is the largest
Use
and to ensure a number is greater than or equal to both others🔗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