AM or PM Check
Take 24-hour time (hours and minutes) and print whether it is AM or PM.
IntermediatePhase 1 - Level 4: Logical Operators & Compound StatementsExample 4 of 10
am-or-pm-check.py
1# Take time2hours = int(input("Enter hours (0-23): "))3minutes = int(input("Enter minutes (0-59): "))45# Determine AM or PM6if hours < 12:7 print("AM")8elif hours == 12:9 print("PM")10else:11 print("PM")
Output
Enter hours (0-23): 10 Enter minutes (0-59): 30 AM Enter hours (0-23): 15 Enter minutes (0-59): 45 PM
What's going on
Check hour value to determine AM/PM.
Key Concepts:
AM: hours 0-11
PM: hours 12-23
12:00 is PM
🔗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