Compare Two Dates
Take two dates (day and month) and determine which one comes first.
AdvancedPhase 1 - Level 5: Creative / Tricky Logical ScenariosExample 8 of 10
compare-two-dates.py
1# Take first date2day1 = int(input("Enter first day: "))3month1 = int(input("Enter first month: "))45# Take second date6day2 = int(input("Enter second day: "))7month2 = int(input("Enter second month: "))89# Compare dates10if month1 < month2:11 print("First date comes earlier")12elif month1 > month2:13 print("Second date comes earlier")14else: # Same month15 if day1 < day2:16 print("First date comes earlier")17 elif day1 > day2:18 print("Second date comes earlier")19 else:20 print("Same date")
Output
Enter first day: 15 Enter first month: 3 Enter second day: 20 Enter second month: 3 First date comes earlier Enter first day: 15 Enter first month: 3 Enter second day: 10 Enter second month: 4 First date comes earlier
What's going on
Compare months first, then days if months are same.
Key Concepts:
Compare months first
If months equal, compare days
Handle all cases: earlier, later, same
🔗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