0

Does anyone understand why it is multiplied by modulo 24?

You look at the clock and see that it is currently 14.00h. You set an alarm to go off 535 hours later. At what time will the alarm go off? Write a program that prints the answer. Hint: for the best solution, you will need the modulo operator. Second hint: The answer is 21.00h, but of course, this exercise is not about the answer, but about how you get it. Input:print (str (14+535%24) + ".00h") Output: 21.00h

18th Dec 2019, 5:31 PM
Esteban Rueda
Esteban Rueda - avatar
2 Respuestas
+ 3
Shouldn't you actually use (14+535)%24 instead of (14+535%24), otherwise there is a small risk to get result that is over 24.
18th Dec 2019, 7:57 PM
Seb TheS
Seb TheS - avatar
0
Multiplied? As for the explanation, think of the clock ticking from a particular time: 14:00h, say. Every 24 hours, a day passes and the time shown will be exactly the same, so all you need to know is the remainder when 535 hours is divided by 24, i.e. 535 modulo 24, or 535 % 24, to tell you how many more hours past the current time the clock will show after 535 hours pass. This happens to be 7, and 14 + 7 is 21, so the time will show 21:00h.
18th Dec 2019, 10:42 PM
Njeri
Njeri - avatar