In this exercise, we're going to write a program
that recreates something that I saw in a blog.
I recently read this book called " "
and it shocked me a little bit
that we only have 4,000 weeks in our lifetime.
And 4,000 is a number that we can all count to.
It's a large number,
but it's still relatively easy to understand.
And there's this great blog post
by Tim Urban called "Your Life in Weeks,"
and if you look in the description pane,
you'll see a link to this blog post.
You can see as he visualizes your 90 year human life
in months and in weeks.
And when it's all there on paper,
and you can see each individual little box,
it kind of shocks you just how little time we have on Earth.
And if you really drill down into it and think about,
well, how many summers do you have
and how many Christmases do you get to spend,
then it all gets a little bit existential.
So, that is the goal.
Today we're going to get existential
and we're going to use programming
and our skills that we've learned
in order to calculate the number of weeks
that we have left in our lifetime.
The goal is to take the input as your age.
So for example, here I've got somebody aged 15,
and we're presuming that they're going to live until 90,
we're going to be optimistic.
And then we're going to calculate
how many weeks they have left in their lifetime.
And we're going to output this as a string
with the exact format that you see in the description box
which is "You have X weeks left."
where X is replaced with the actual number of weeks
that you have calculated.
Pause the video, think about how you might do this,
and try to complete this challenge.
All right, let's go through the solution.
The first thing we need to calculate
is how many years they have left.
So we're going to take 90
and we're going to subtract it by their age.
But again, remember that the input comes in
as a string data type.
In order to convert it into a whole number, an integer,
we need to wrap the int() function around the age,
just like what you see on line 3.
In order to get to the number of weeks
that that year is representing,
we can drill it down through months
or we can directly go there through the number of weeks.
There are 52 weeks in a year,
so we can simply multiply what's stored
in the number of years by 52.
If somebody was aged 41,
then 90 - 41 = 49,
and then 49 multiplied by 52
is 2,548 weeks.
Finally, we can print out using an f-string,
telling the user they have however many weeks left,
and we're substituting the weeks variable
into the f-string using the curly braces here.
And there you have it, that's the solution.