Novice · Formatting · 49 of 264
Clock time
Read hours and minutes and print the time as HH:MM, with leading zeros.
Input: hours (0-23) and minutes (0-59), one per line. Output: HH:MM, e.g. 07:05 Tip: f"{n:02d}" shows n with at least two digits.
Examples
Input
7 5
Output
07:05
Input
12 30
Output
12:30
Input
0 0
Output
00:00
One more test checks other inputs when you press Check.
Stuck? The idea behind formatting
An f-string puts values into text: f"{name} is {age}". Inside the braces, a format after a colon controls how the value looks.
:.2f gives two decimal places, :5 makes room for five characters, :>5 lines up to the right, :05 fills with zeros.
price = 3.5
print(f"Total: £{price:.2f}")
print(f"{7:03}") # 007Watch for: round() can drop a trailing zero (3.50 becomes 3.5); :.2f always shows two places.