Lesson 1.10 · Write it
Minutes to hours
A whole programPython or Java5 tests, 3 of them hidden
On a phone? Put the lines in order instead
Write a program that reads a number of minutes (a whole number, 0 or more) and prints it as hours and minutes on one line:
1 h 40 min
- The hours come from whole-number division by 60.
- The minutes left come from the remainder after dividing by 60.
- The format is the hours, then
h, then the remaining minutes, thenmin. - Print nothing else. Spaces at the end are ignored.
Your program is run several times. Only what it prints is checked.
In Python, use // for whole-number division and % for the remainder. In Java, / between two ints already gives the whole number.
Running Java here comes later. You can put this answer's lines in order instead. You can still write your Java answer (it stays while this page is open) and compare it with our worked solution. Or try this exercise in Python.
Examples
Your program is run 5 times: the 2 examples below, and 3 hidden ones that check the rules above. Only what it prints is checked.
more than an hour (rules 1 to 4)
You type
- typed: 100
It prints
1 h 40 min
less than an hour (rules 1 and 2)
You type
- typed: 59
It prints
0 h 59 min