Python Program to Convert Days into Years, Weeks, and Days

This article is created to cover the program in Python that converts given days by the user at run-time into years, weeks, and days.

The question is: write a Python program to convert the number of days into years, weeks, and days. The following program is the answer to this question:

print("Enter the Number of Days: ")
num = int(input())

year = int(num/365)
week = int((num%365)/7)
days = int((num%365)%7)

print("Total Number of Year(s): ")
print(year)
print("Total Number of Week(s):")
print(week)
print("Total Number of Day(s):")
print(days)

Here is its sample run:

python convert days into years weeks days

Now supply the input "385" as the total number of days to convert it into year(s), week(s), and day(s) as shown in the snapshot given below:

convert days into years weeks days

Modified Version of the Previous Program

The "end" in this program used to skip the printing of an automatic newline. "str()" converts any type of value to a string type. This method is used to convert all the things into strings and concatenate all the strings using the plus (+) operator.

print(end="Enter the Number of Days: ")
num = int(input())

year = int(num/365)
week = int((num%365)/7)
days = int((num%365)%7)

print("\nYear: "+str(year)+", Week: "+str(week)+", Day: "+str(days))

Here is its sample run with the same user input as the previous program's sample run:

convert days into years weeks python

Python Online Test


« Previous Program Next Program »


Liked this post? Share it!