Clock Angle Calculation

Take time (hours and minutes) and print the smaller angle between the hour and minute hands.

Logic BuildingAdvanced
Logic Building
# Take time
hours = int(input("Enter hours (1-12): "))
minutes = int(input("Enter minutes (0-59): "))

# Calculate angles
hour_angle = (hours % 12) * 30 + minutes * 0.5
minute_angle = minutes * 6

# Find smaller angle
angle = abs(hour_angle - minute_angle)
smaller_angle = min(angle, 360 - angle)

print(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

Calculate angles of hour and minute hands.

Key Concepts:

  • Hour hand: (hours % 12) * 30 + minutes * 0.5
  • Minute hand: minutes * 6
  • Find absolute difference
  • Take smaller of angle and 360 - angle