1
00:00:01,620 --> 00:00:04,890
In this exercise, we're going to write a program

2
00:00:04,890 --> 00:00:09,870
that recreates something that I saw in a blog.

3
00:00:09,870 --> 00:00:12,840
I recently read this book called " "

4
00:00:12,840 --> 00:00:14,670
and it shocked me a little bit

5
00:00:14,670 --> 00:00:19,620
that we only have 4,000 weeks in our lifetime.

6
00:00:19,620 --> 00:00:22,470
And 4,000 is a number that we can all count to.

7
00:00:22,470 --> 00:00:23,700
It's a large number,

8
00:00:23,700 --> 00:00:27,990
but it's still relatively easy to understand.

9
00:00:27,990 --> 00:00:29,670
And there's this great blog post

10
00:00:29,670 --> 00:00:32,729
by Tim Urban called "Your Life in Weeks,"

11
00:00:32,729 --> 00:00:34,710
and if you look in the description pane,

12
00:00:34,710 --> 00:00:37,590
you'll see a link to this blog post.

13
00:00:37,590 --> 00:00:42,590
You can see as he visualizes your 90 year human life

14
00:00:42,900 --> 00:00:45,600
in months and in weeks.

15
00:00:45,600 --> 00:00:47,820
And when it's all there on paper,

16
00:00:47,820 --> 00:00:50,790
and you can see each individual little box,

17
00:00:50,790 --> 00:00:55,790
it kind of shocks you just how little time we have on Earth.

18
00:00:56,040 --> 00:00:58,980
And if you really drill down into it and think about,

19
00:00:58,980 --> 00:01:01,170
well, how many summers do you have

20
00:01:01,170 --> 00:01:04,440
and how many Christmases do you get to spend,

21
00:01:04,440 --> 00:01:07,320
then it all gets a little bit existential.

22
00:01:07,320 --> 00:01:09,810
So, that is the goal.

23
00:01:09,810 --> 00:01:11,970
Today we're going to get existential

24
00:01:11,970 --> 00:01:13,860
and we're going to use programming

25
00:01:13,860 --> 00:01:15,330
and our skills that we've learned

26
00:01:15,330 --> 00:01:17,430
in order to calculate the number of weeks

27
00:01:17,430 --> 00:01:20,160
that we have left in our lifetime.

28
00:01:20,160 --> 00:01:25,050
The goal is to take the input as your age.

29
00:01:25,050 --> 00:01:28,890
So for example, here I've got somebody aged 15,

30
00:01:28,890 --> 00:01:32,280
and we're presuming that they're going to live until 90,

31
00:01:32,280 --> 00:01:34,050
we're going to be optimistic.

32
00:01:34,050 --> 00:01:35,430
And then we're going to calculate

33
00:01:35,430 --> 00:01:38,910
how many weeks they have left in their lifetime.

34
00:01:38,910 --> 00:01:42,030
And we're going to output this as a string

35
00:01:42,030 --> 00:01:45,630
with the exact format that you see in the description box

36
00:01:45,630 --> 00:01:48,960
which is "You have X weeks left."

37
00:01:48,960 --> 00:01:52,860
where X is replaced with the actual number of weeks

38
00:01:52,860 --> 00:01:54,123
that you have calculated.

39
00:01:55,320 --> 00:01:58,590
Pause the video, think about how you might do this,

40
00:01:58,590 --> 00:02:00,543
and try to complete this challenge.

41
00:02:04,230 --> 00:02:06,180
All right, let's go through the solution.

42
00:02:06,180 --> 00:02:07,860
The first thing we need to calculate

43
00:02:07,860 --> 00:02:10,560
is how many years they have left.

44
00:02:10,560 --> 00:02:12,390
So we're going to take 90

45
00:02:12,390 --> 00:02:15,690
and we're going to subtract it by their age.

46
00:02:15,690 --> 00:02:18,780
But again, remember that the input comes in

47
00:02:18,780 --> 00:02:21,000
as a string data type.

48
00:02:21,000 --> 00:02:25,680
In order to convert it into a whole number, an integer,

49
00:02:25,680 --> 00:02:30,060
we need to wrap the int() function around the age,

50
00:02:30,060 --> 00:02:32,343
just like what you see on line 3.

51
00:02:34,020 --> 00:02:36,450
In order to get to the number of weeks

52
00:02:36,450 --> 00:02:40,500
that that year is representing,

53
00:02:40,500 --> 00:02:43,740
we can drill it down through months

54
00:02:43,740 --> 00:02:47,970
or we can directly go there through the number of weeks.

55
00:02:47,970 --> 00:02:51,210
There are 52 weeks in a year,

56
00:02:51,210 --> 00:02:54,330
so we can simply multiply what's stored

57
00:02:54,330 --> 00:02:57,480
in the number of years by 52.

58
00:02:57,480 --> 00:03:00,300
If somebody was aged 41,

59
00:03:00,300 --> 00:03:03,840
then 90 - 41 = 49,

60
00:03:03,840 --> 00:03:07,680
and then 49 multiplied by 52

61
00:03:07,680 --> 00:03:12,090
is 2,548 weeks.

62
00:03:12,090 --> 00:03:15,900
Finally, we can print out using an f-string,

63
00:03:15,900 --> 00:03:19,860
telling the user they have however many weeks left,

64
00:03:19,860 --> 00:03:23,070
and we're substituting the weeks variable

65
00:03:23,070 --> 00:03:26,253
into the f-string using the curly braces here.

66
00:03:27,510 --> 00:03:29,660
And there you have it, that's the solution.

