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:
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:
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.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/python-exercises/python-basic-exercise-62.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics