On day 2 I wrote a program to calculate how many days, weeks and months someone would have left based on their age in years and assuming they lived to 90.
I started with a variable called age that prompts the user for their age.
Then I created 3 additional variables: age_in_days, age_in_weeks and age_in_months.
Each variable holds either the number 365 (days), 52 (weeks) or 12 (months). They then get multiplied by the age the user input as their current age.
Afterwards, I created another 3 variables that hold the following calculations:
remaining_days = 365 * 90 - age_in_days
remaining_weeks = 52 * 90 - age_in_weeks
remaining_months = 12 * 90 - age_in_months
Finally I used the following print function:
print(f"You have {remaining_days} days, {remaining_weeks} weeks, and {remaining_months} months left.")
Below is an example of what happens when this code runs:
What is your current age? 25
You have 23725 days, 3380 weeks, and 780 months left.
Top comments (0)