if (timeH,timeM)>(2,0): # if it is after 2 am timeH1=timeH+5 if timeH1>=24:#deduct 24 hrs whenever it over 24 timeH1=timeH1-24 else: timeH1=timeH+4
can be changed to: timeH1 = (timeH + 5)% 24
and you also need to check another case and subtract 24 that you are not doing right now.
joel goldstick
source share