All language subtitles for 023 [Interactive Coding Exercise] Life in Weeks.en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French Download
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

1

So you should see a day 2.3, Your Life in Weeks

2

and this is the challenge that we're going to complete in this lesson.

3

The idea is that there's a really great article by Tim Urban of wait

4

but why on visualizing your life in weeks.

5

And I was reading this recently and it really made an impact on me,

6

especially when you see that a whole life from age zero to 90 can be mapped out

7

like this in weeks where every week is represented by little check box.

8

And you can see each of these boxes, right?

9

This is like how many weeks you have in your whole life.

10

And it's not as small as I thought it would be.

11

I thought each of these boxes would be like invisible because they're so tiny

12

because I have so many weeks in my life. But it's actually not true.

13

There's actually not that many. So in today's coding challenge,

14

what I want you to do is to create a program using the mathematical operations

15

that you've learned about as well as the f-strings that you learned about in the

16

last lesson to tell us how many days, weeks, and months we actually have left

17

if we were lucky enough to live until 90 years old.

18

The code is going to ask you for your current age,

19

let's say that I'm 12.

20

And then it's going to calculate the number of days,

21

weeks, and months you have left in your life

22

if you lived until 90.

23

And then it's going to print it out to you like so.

24

And the important premise of this code challenge for all of the tests to pass is

25

that there are 365 days in a year,

26

52 weeks in a year and 12 months in a year. I know that because of leap year,

27

it's actually a little bit more than that. But for this exercise sake,

28

let's just call it for 365, 52 and 12.

29

Pause the video and see if you can complete this challenge and then head back

30

over here and we'll walk through the solution together.

31

All right. How did that exercise go? I'm sorry

32

it's a little bit dark making you think about how many days, weeks,

33

and months you have left in life, but you can think about it as a motivation,

34

right? If I only have 400 months left,

35

I don't know if I want to spend one of those months just watching game of

36

Thrones. Maybe I want to do something for other people.

37

Maybe I want to create something. So how are we going to calculate this?

38

Well, we've got a hold of the age from the input,

39

but you might remember from previous lessons that the input always creates a

40

string datatype. In order to do math,

41

we do still have to do a type conversion.

42

So we have to change our age into a number. So let's call it age_

43

as_int. Age is never going to be a float, right?

44

Because not many people are going to tell you that they are 56.4 years old.

45

So we're going to accept this as a whole number.

46

So we'll convert our age into an int.

47

Now the next stage is we have to do some calculations. We have to calculate,

48

um, the number of years left, right?

49

So let's call it years_remaining and that's going to be equal to 90,

50

so we're presuming we're going to live to 90, minus age_

51

as_int. So now that we've got the number of years remaining,

52

we can calculate the number of days, weeks, and months left.

53

So days_remaining is going to be equal to years_remaining multiplied by

54

55

because there are 365 days in a year.

56

And then we can do the same for weeks,

57

and months.

58

So now that I've got hold of the number of days remaining, weeks remaining and

59

months remaining, then I'm ready to actually use it inside my string.

60

But before we do that,

61

it's always helpful to check your code as you go along to make sure that it

62

works exactly as you expect it to.

63

So let's go ahead and try to print what is the number of months remaining.

64

So if we go ahead and run our code,

65

and let's say that we're 80 years old, right?

66

Which means that we'll have 10 years remaining and we will have 120 months

67

remaining. So all of that looks pretty good to me.

68

So the next thing we have to do is to somehow output the sentence where it says

69

you have X days, Y weeks and Z months left.

70

So let's copy that and paste that sentence in here.

71

And then I'm going to turn it into a string by wrapping it inside a set of

72

double quotes. Now that I've got a string,

73

I can turn it into an f-string by putting the character F before the string.

74

And instead of having X, Y, and Z,

75

I can replace them with some curly braces inside of which I can put my variable

76

names. So I'll change this to days_remaining,

77

this to weeks_remaining,

78

and this to months_remaining.

79

And now that I've got my string, I have two options.

80

I can either just wrap this inside a print statement and print it as it is.

81

But what I think might actually make it easier to read is to save it inside a

82

separate variable, called message. And then in the next line,

83

I can simply print my message. It does exactly the same thing,

84

but I think this is a little bit easier to read.

85

So now let's go ahead and run our code and see if we get any errors.

86

It's asking us for our current age, let's say we're 67 years old. Well,

87

then we only have 8,395 days and 1,196 weeks and 276 months.

88

So I hope you managed to get this code challenge right.

89

And even though the challenge is a little bit dark, well,

90

at least remember that when you become a really good programmer,

91

you'll be able to cut down on a lot of the boring things and repetitive tasks in

92

life. So at least you will be claiming back some of those days, weeks,

93

and months.

94

So I hope you had fun with me on this code challenge. In the next lesson

95

I've got a quiz for you. So head over there and to give it a go.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.