Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
simple angles solution in Clear category for Clock Angle by PetrStar
def clock_angle(time):
h, m = map(int, time.split(':'))
angle_h = h % 12 * 30 + m % 60 * 0.5
angle_m = m * 6
return min((st:=abs(angle_h-angle_m)), 360 - st)
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert clock_angle("02:30") == 105, "02:30"
assert clock_angle("13:42") == 159, "13:42"
assert clock_angle("01:42") == 159, "01:42"
assert clock_angle("01:43") == 153.5, "01:43"
assert clock_angle("00:00") == 0, "Zero"
assert clock_angle("12:01") == 5.5, "Little later"
assert clock_angle("18:00") == 180, "Opposite"
Dec. 27, 2020