Python Program to Convert the Days into Years, Weeks, and Days
ADVERTISEMENTS
Python program to convert the days into years, weeks, and days.
In this article, you will learn how to convert the days into years, weeks, and days in the python language.
You should have the knowledge of the following topics in python programming to understand this program:
- Python
print()
function - Python
input()
function
Base Knowledge
1Year = 365days
1Week = 7days
Standard formula to calculate the year, weeks, and days
y = (d / 365)
w = (d % 365) / 7
d = d - ((y * 365) + (w))
Where
y = year
w = week
d = day
Source Code
# Python Program to Convert the Days into Years, Weeks, and Days
print("Enter the days::")
d, y, w = int(input()), None, None
# d = days
# y = years
# w = weeks
# Conversion of days in to years, weeks and days
y = (int)(d / 365)
w = (int)((d % 365) / 7)
d = (int)(d - ((y * 365) + (w)))
# Output
print(y, " Year, ", w, " Weeks, and ", d, " Days\n")
Output
Enter the days::
464
1 Year, 14 Weeks, and 85 Days
Explanation
In this above program, we have taken an input 464
number of total days then used the standard formula to calculate the number of years, number of weeks, and number of days then It returned the following values:
- 1 Year
- 14 Weeks
- 85 Days