Explore

Close
Python Programs Share

Python Program To Calculate Seconds In Year Month Week And Day

Python Program To Calculate Seconds In Year Month Week And Day

Want to know how to create a python program to calculate seconds in a year, month, week and day. Then you are at the right place today in this tutorial I will show you how to create this program so read till the end.

This is a simple python program, I will show you exactly how to do it and provide you the code of this program below are queries we will solve:

  • Python program to calculate number of seconds in a year.
  • Python program to calculate number of seconds in a month.
  • Python Program to calculate number of seconds in a week.
  • Python program to calculate number of seconds in a day.

Above are all the 4 programs I will show you how to do, so now let’s see how to do these programs in code.

Python program to calculate number of seconds in a year


#Python program to print the Number of seconds in Year

days_in_year = 365
hours_in_day = 24
minutes_in_hour = 60
seconds_in_minute = 60

result = days_in_year * hours_in_day * minutes_in_hour * seconds_in_minute

print(f"Number of seconds in a year are: {result}")

Above is the python program to calculate the number of seconds in a year. In this program we multiply seconds in a minute by minutes in an hour by hours in a day by days in a year, which gives us the number of seconds in a year.

Output


Number of seconds in a year are: 31536000

Python program to calculate number of seconds in a month.


#Python program to print the Number of seconds in month

days_in_month = 31 
hours_in_day = 24
minutes_in_hour = 60
seconds_in_minute = 60

result = days_in_month * hours_in_day * minutes_in_hour * seconds_in_minute

print(f"Number of seconds in a month are: {result}")

Above is the python program to calculate seconds in a month. In this program we multiply seconds in a minute by minutes in an hour by hours in a day by days in a month, which gives us the number of seconds in a month.

Output


Number of seconds in a month are: 2678400

Python program to calculate number of seconds in a week.


#Python program to print the Number of seconds in week

days_in_week = 7
hours_in_day = 24
minutes_in_hour = 60
seconds_in_minute = 60

result = days_in_week * hours_in_day * minutes_in_hour * seconds_in_minute

print(f"Number of seconds in a week are: {result}")

Above is the python program to calculate seconds in a week. In this program we multiply seconds in a minute by minutes in an hour by hours in a day by days in a week, which gives us the number of seconds in a week.

Output


Number of seconds in a week are: 604800

Python program to calculate number of seconds in a day.


#Python program to print the Number of seconds in day

hours_in_day = 24
minutes_in_hour = 60
seconds_in_minute = 60

result = hours_in_day * minutes_in_hour * seconds_in_minute

print(f"Number of seconds in a day are: {result}")

Above is the python program to calculate the number of seconds in a day. In this program we multiply seconds in a minute by minutes in an hour by hours in a day, which gives us the number of seconds in a day.

Output


Number of seconds in a day are: 86400

Combination Of All Programs In One Program


# Python program to print the Number of seconds in all

days_in_year = 365
days_in_month = 31
days_in_week = 7
hours_in_day = 24
minutes_in_hour = 60
seconds_in_minute = 60

seconds_in_year = days_in_year * hours_in_day * minutes_in_hour * seconds_in_minute
seconds_in_month = days_in_month * hours_in_day * minutes_in_hour * seconds_in_minute
seconds_in_week = days_in_week * hours_in_day * minutes_in_hour * seconds_in_minute
seconds_in_day = hours_in_day * minutes_in_hour * seconds_in_minute

print(f"Number of seconds in a year are: {seconds_in_year}")
print(f"Number of seconds in a month are: {seconds_in_month}")
print(f"Number of seconds in a week are: {seconds_in_week}")
print(f"Number of seconds in a day are: {seconds_in_day}")

Above is the program which is the combination of all the programs into one program. This program will print the number of seconds in year, month, week and day.

Output


Number of seconds in a year are: 31536000
Number of seconds in a month are: 2678400
Number of seconds in a week are: 604800
Number of seconds in a day are: 86400

How to run these programs?

To run this program you can run it on your computer if you have python installed or you can use an online python compiler to run each program.

If you want to install python on your computer, then you can refer to this guide: Install and setup python on your computer.

Summary

These were all the python programs to calculate the number of seconds in a year, month, week and a day. I hope you found this guide helpful and useful. Do share it with your friends who might be interested.

Here are some more python programs for you:

I hope you found what you were looking for from this tutorial. If you want more python tutorials like this, do join our Telegram channel for future updates.

Thanks for reading, have a nice day 🙂