Take Two Numbers and Print the Larger One
Compare two numbers and print the larger one.
BeginnerPhase 1 - Level 1: Simple ConditionsExample 6 of 10
take-two-numbers-and-print-the-larger-one.py
1# Take two numbers as input2num1 = float(input("Enter first number: "))3num2 = float(input("Enter second number: "))45# Find and print larger number6if num1 > num2:7 print(f"Larger number: {num1}")8elif num2 > num1:9 print(f"Larger number: {num2}")10else:11 print("Both numbers are equal")
Output
Enter first number: 10 Enter second number: 20 Larger number: 20.0
What's going on
Compare two numbers using relational operators.
Key Concepts:
Use
> to check if first number is greaterUse
elif to check if second number is greaterUse
else for the case when both are equal🔗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