Add hours on a clock without using “mod” (12-hour clock)

Challenge Level: Growing experience

Learning outcomes

Students will be able to:

Requirement:

Write a program that adds hours on a clock without using the “mod” operator. You need to keep subtracting 12 from the new time (original time + hours to add) until the new time is less than or equal to 12.

Testing examples:

Your program should display the outputs shown in this table for the given inputs provided;

Input Output
11
1
The new time is 12 o'clock.
11
4
The new time is 3 o'clock.
11
12
The new time is 11 o'clock.
11
72
The new time is 11 o'clock.

Languages

Scratch

What it should look like

Click on the green flag to see the expected output of your program.

Recommended blocks
when green flag clicked
set [original time v] to (answer)

set [hours to add v] to (answer)

set [new time v] to ((original time) + (hours to add))

change [new time v] by (-12)
ask [Enter a time:] and wait

ask [Enter the number of hours to add:] and wait
say (join [The new time is ] (join (new time) [ o'clock.]))
repeat until <<(new time) < [12]> or <(new time) = [12]>>
end
Hints
  • Make variables called “original time” and “hours to add” and set their values to the inputs entered by the user. Make a variable called “new time” and set its value to the sum of the “original time” and “hours to add”. Keep subtracting 12 from the “new time” until the “new time” is less than or equal to 12. Display the value of the “new time” as the output.

Show Scratch solution

Python