GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • w3resource
  • Front End
  • HTML
  • CSS
  • JavaScript
  • HTML5
  • Schema.org
  • php.js
  • Twitter Bootstrap
  • Responsive Web Design tutorial
  • Zurb Foundation 3 tutorials
  • Pure CSS
  • HTML5 Canvas
  • JavaScript Course

This view

  • Original page
  • New address

GeezerVison is showing www.w3resource.com — Python: Convert all units of time into seconds - w3resource

Python: Convert all units of time into seconds

Last update on May 17 2025 05:43:25 (UTC/GMT +8 hours)


Time to Seconds Converter

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.


For more Practice: Solve these Related Problems:

  • Write a Python program to convert a given number of seconds into weeks, days, hours, minutes, and seconds.
  • Write a Python program to calculate the total number of seconds in a given number of months (assuming 30 days per month).
  • Write a Python program to take a duration in hours, minutes, and seconds and convert it into milliseconds.
  • Write a Python program to convert a given number of microseconds into hours, minutes, and seconds.

Go to:

  • Python Basic Exercises Home ↩
  • Python Exercises Home ↩

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.

Python Code Editor:

 

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.


  • Daily Coding Challenges & Projects
  • Weekly Trends and Language Statistics



You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.