angle = {12:0,1:30,2:60,3:90,4:120,5:150,6:180,7:210,8:240,9:270,10:300,11:330, 0: 0}
n = [1,2,3,4,5,6,7,8,9,10,11,12]
def hr(arr, h, m, s):
f = lambda x: arr.index(x if x > 0 else 12)
hh = h + 1 if h < 12 else 1
a = angle[f(hh)] - angle[f(h)]
if a < 0:
a += 360
# print("hour ", h, hh, angle[f(h)], angle[f(hh)], a)
res = angle[f(h)] + (m + s / 60) / 60 * a
return res
def mn(arr, m, s):
f = lambda x: arr.index(x if x > 0 else 12)
e = m // 5
ee = e + 1 if e < 12 else 1
print("e :", e, ee, f(e), f(ee))
a = angle[f(ee)] - angle[f(e)]
if a < 0:
a += 360
# print("rem :", m - 5 * e)
# print("e :", e, ee, f(e), f(ee), a)
# print(angle[f(e)], angle[f(ee)])
res = angle[f(e)] + (m + s / 60 - 5 * e) / 5 * a
return res
def clock_angle(arr, h, m, s):
x = hr(arr, h, m, s)
y = mn(arr, m, s)
z = x - y
if z < 0:
z += 360
return min(z, 360 - z)
# arr = [1,7,2,8,3,9,4,10,5,11,6,12]
arr = n
h, m, s = 7, 2, 0
print(hr(arr, h, m, s))
print(mn(arr, m, s))
print(clock_angle(arr, h, m, s))
To embed this project on your website, copy the following code and paste it into your website's HTML: