Convert seconds to hour, minute and seconds in Python
input() - Question 17
In this question, we will see how to input total time in seconds in Python programming using the input() function and print the time in hours, minutes and seconds. To know more about input() function click on the input() function lesson.
Q17) Write a program in Python to input total time in seconds and print the time in hours, minutes and seconds.
Total Seconds: 4206
Hour: 1
Minutes: 10
Seconds: 6
Program
ts=int(input('Enter total seconds '))
h=ts//3600
m=(ts%3600)//60
s=(ts%3600)%60
print('Hours={}'.format(h))
print('Minutes={}'.format(m))
print('Seconds={}'.format(s))
Output
Enter total seconds 4830 Hours=1 Minutes=20 Seconds=30