226k views
2 votes
3.19 Clone of LAB: Convert to seconds in PYTHON

Write a program that reads in hours, minutes, and seconds as input, and outputs the time in seconds only.
Ex: If the input is:
1
6
40
where 1 is the number of hours, 6 is the number of minutes, and 40 is the number of seconds, the output is:
Seconds: 4000\
If this helps its the solution kind of:
# get the number of hours, minutes, and seconds from the user
hours = int(input())
minutes = int(input())
seconds = int(input())
# calculate number of seconds from hours (3600 seconds in an hour)
seconds += hours * 3600
# calculate number of seconds from minutes (60 seconds in a minute)
seconds += minutes * 60
print(f'Seconds: {seconds}')

User Peralta
by
8.6k points

1 Answer

4 votes

This is a Python program that reads the number of hours, minutes, and seconds as input and converts the time to seconds:

How to write the code in Python

# get the number of hours, minutes, and seconds from the user

hours = int(input("Enter the number of hours: "))

minutes = int(input("Enter the number of minutes: "))

seconds = int(input("Enter the number of seconds: "))

# calculate number of seconds from hours (3600 seconds in an hour)

seconds += hours * 3600

# calculate number of seconds from minutes (60 seconds in a minute)

seconds += minutes * 60

print(f'Seconds: {seconds}')

User Alxp
by
9.0k points