Dremendo Tag Line

Convert time in seconds in Python

input() - Question 16

In this question, we will see how to input time in hours, minutes and seconds in Python programming using the input() function and print the total time only in seconds. To know more about input() function click on the input() function lesson.

Q16) Write a program in Python to input time in hours, minutes and seconds and print the total time only in seconds.

Hour: 1
Minutes: 10
Seconds: 6
Total Seconds: 4206

Program

h=int(input('Enter hours '))
m=int(input('Enter minutes '))
s=int(input('Enter seconds '))
ts=(h*3600)+(m*60)+s
print('Total time in seconds={}'.format(ts))

Output

Enter hours 1
Enter minutes 20
Enter seconds 30
Total time in seconds=4830
video-poster