easy +8 pts

Minutes to Hours: Time Conversion Helper

Convert minutes into a human-readable 'Xh Ym' format without extra libraries.

Write a function `minutes_to_hours(minutes)` that takes a non-negative integer `minutes` and returns a string representing that duration in hours and minutes using a compact format. Rules: - If `minutes` is 0, return `"0m"`. - If `minutes` is less than 60, return just the minutes followed by `"m"` (e.g., `"45m"`). - If `minutes` is exactly a multiple of 60 (i.e., hours is ≥1 and minutes part is 0), return just the hours followed by `"h"` (e.g., `"2h"`). - Otherwise, return `"{hours}h {remaining_minutes}m"` (e.g., `"1h 30m"`). No rounding—only integer division and modulo are used. The input will always be a non-negative integer.

Constraints

Input is a non-negative integer. The output must be a string exactly as specified. No imports required.

Example

>>> minutes_to_hours(0)
'0m'
>>> minutes_to_hours(45)
'45m'
>>> minutes_to_hours(60)
'1h'
>>> minutes_to_hours(90)
'1h 30m'
>>> minutes_to_hours(150)
'2h 30m'
8 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use `divmod(minutes, 60)` to get hours and remainder.
Check if `hours == 0` or `remaining == 0` for special cases.
Build the string only when both parts are non-zero.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.