In: Computer Science
Determine where the short hand and long hands meet on the clock. Involve minute and second in the expression (no longer fraction such as 5.45 but 5 minutes 60x0.45=27 seconds). Run full 12 hours for AM or PM. Use python to solve this problem. Use numpy if needed.
CODE:
#minuteHandAngle is the angle that the long hand sweeps at any
given second
#hourHandAngle is the angle that the short hand sweeps at any given
second
minuteHandAngle = 0
hourHandAngle = 0
#this list stores the times where the short hand and the long hand
meet
meetAt = []
#runnning a loop for 12 hours or 43200 seconds where i denotes each
second
for i in range(12*60*60 + 1):
#the minute or long hand sweeps 1 degree every 10 seconds therefore
360 degrees in 3600 seconds
if(i%10 == 0):
minuteHandAngle += 1
#after every hour the minute hand starts from the beggining
if(minuteHandAngle%360 == 0):
minuteHandAngle = 0
#the hour hand sweeps 360 degrees in 12 hours or 12*60*60 seconds
or 43200 seconds
#so hour hand sweeps 1 degree after every 120 seconds
if(i%120 == 0):
hourHandAngle += 1
#if at any time the hour hand and the minute hand are at the same
angle
#they are at same position
if(hourHandAngle == minuteHandAngle):
meetingTime =
str(int(i/3600))+":"+str(int(i/60)-int(i/3600)*60)
if(meetingTime not in meetAt):
#displaying the times the short hand and long hand meet
print("Both hands meet at: {}:{}
A.M.".format(str(int(i/3600)),str(int(i/60)-int(i/3600)*60)))
meetAt.append(meetingTime)
__________________________________________
CODE IMAGES AND OUTPUT:
______________________________________________
Feel free to ask any questions in the comments section
Thank You!