w3resource

Python: Convert all units of time into seconds

Python Basic: Exercise-62 with Solution

Write a Python program to convert all units of time into seconds.

Pictorial Presentation:

Convert all units of time into seconds

Sample Solution:-

Python Code:

# Prompt the user to input a number of days and store it in the variable 'days'.
days = int(input("Input days: ")) * 3600 * 24
# Prompt the user to input a number of hours and store it in the variable 'hours'.
hours = int(input("Input hours: ")) * 3600
# Prompt the user to input a number of minutes and store it in the variable 'minutes'.
minutes = int(input("Input minutes: ")) * 60
# Prompt the user to input a number of seconds and store it in the variable 'seconds'.
seconds = int(input("Input seconds: "))
# Calculate the total time in seconds by adding the converted values.
time = days + hours + minutes + seconds
# Print the total time in seconds.
print("The amount of seconds:", time)

Sample Output:

Input days:  4
Input hours:  5
Input minutes:  20
Input seconds:  10
The  amounts of seconds 364810

Flowchart:

Flowchart: Convert all units of time into seconds.

Python Code Editor:

 

Previous: Write a Python program to convert the distance (in feet) to inches, yards, and miles.
Next: Write a Python program to get an absolute file path.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.