Python Program to Convert Days into Years, Weeks & Days

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

The question is, write a Python program to convert number of days into years, weeks and days. 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 say 385 as 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 Previous Program

The end in this program, used to skip printing of an automatic newline. The str() converts any type of value to a string type. This method is used to convert all the things into string and concatenate all strings using 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 same user input as of previous program's sample run:

convert days into years weeks python

Python Online Test


« Previous Program Next Program »