Logic Building
# Take time
hours = int(input("Enter hours (0-23): "))
minutes = int(input("Enter minutes (0-59): "))
# Determine AM or PM
if hours < 12:
print("AM")
elif hours == 12:
print("PM")
else:
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
Check hour value to determine AM/PM.
Key Concepts:
- AM: hours 0-11
- PM: hours 12-23
- 12:00 is PM