Seconds to Time
Programming Basics · Python
TASK
Problem
Given seconds `s` from the start of a day, print hours, minutes, and seconds separated by spaces.
EXAMPLE
Example
3665
1 1 5
LIMITS
Constraints
0 ≤ s < 86,400
LEARN
Theory for this problem
+
`input()` reads data entered by the user. The result of `input()` is initially a string. `int()` converts a numeric string into an integer. The `//` operator performs integer division and keeps the whole-number part. The `%` operator returns the remainder after division. `print()` displays the program result. Print only what the problem statement requires.
**Connection to this task.** The `//` and `%` operators complement each other: the first gives the integer quotient and the second gives the remainder. This is useful when splitting a number into groups or digits. The expression `h` shows how this idea is applied to the task data.
NEED HELP?
Hints
+
['Find hours first, then split the remainder after division by 3600 into minutes and seconds.']
ANSWER
Solution
+
s = int(input()) h = s // 3600 m = s % 3600 // 60 sec = s % 60 print(h, m, sec)