Clock Angle Calculation
Find the smaller angle between clock hands with Python. Students account for the moving hour hand and compare the two arcs on a twelve-hour clock face.
1# Take time2hours = int(input("Enter hours (1-12): "))3minutes = int(input("Enter minutes (0-59): "))45# Calculate angles6hour_angle = (hours % 12) * 30 + minutes * 0.57minute_angle = minutes * 689# Find smaller angle10angle = abs(hour_angle - minute_angle)11smaller_angle = min(angle, 360 - angle)1213print(f"Smaller angle: {smaller_angle} degrees")
Output
Enter hours (1-12): 3 Enter minutes (0-59): 30 Smaller angle: 75.0 degrees Enter hours (1-12): 12 Enter minutes (0-59): 0 Smaller angle: 0.0 degrees
In this one
- Model moving clock hands
- Compute an absolute angular gap
- Choose the smaller arc
How it works
- 1
Calculate hour and minute angles.
- 2
Take the absolute difference between them.
- 3
Choose min(angle, 360 - angle) and print.
Edge cases
Why use hours % 12?
Why use hours % 12?
It maps twelve to the same starting position as zero.
What happens at 12:00?
What happens at 12:00?
Both hand angles are zero, so the smaller angle is zero.
What's going on
The hour hand moves half a degree each minute, not just thirty degrees at the hour. The formula combines the hour position with that minute-by-minute movement.
The minute hand moves six degrees per minute. abs finds the direct gap, and min compares that gap with the complementary arc around the full circle. At 3:30 the hour hand is at 105 degrees and the minute hand at 180, giving 75 degrees.
Why use hours % 12? It maps twelve to the same starting position as zero.
What happens at 12:00? Both hand angles are zero, so the smaller angle is zero.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Why not use hours * 30 alone?
Pick an answer to check it.
Question 2
Why use hours % 12?
Pick an answer to check it.
Questions people ask
Why use hours % 12?
It maps twelve to the same starting position as zero.
What happens at 12:00?
Both hand angles are zero, so the smaller angle is zero.
Why not use hours * 30 alone?
The hour hand also moves during the hour.
๐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