All language subtitles for 22. Exercise Type Conversion

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
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 Download
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
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,640 --> 00:00:01,740 Welcome back. 2 00:00:01,750 --> 00:00:08,830 So up until now we've learned about integers floats strings and volume values. 3 00:00:08,830 --> 00:00:12,580 So let's try and tie some of those things together. 4 00:00:12,670 --> 00:00:14,740 Let's imagine you are Facebook. 5 00:00:15,430 --> 00:00:17,350 How do you think Facebook works. 6 00:00:17,380 --> 00:00:26,480 Underneath the hood when it comes to your profile well would have let's say a variable called name. 7 00:00:26,880 --> 00:00:33,450 And this will have your name and then they'll probably have a variable with your age. 8 00:00:34,520 --> 00:00:41,770 Let's say 50 not actually 50 but I'm pretending to be for this case just so I sound wiser and then let's 9 00:00:41,770 --> 00:00:45,320 say relationship status. 10 00:00:45,430 --> 00:00:49,900 So again we also have relationship status on Facebook. 11 00:00:50,110 --> 00:00:57,280 And for now let's say single so that's my Facebook profile right there. 12 00:00:57,280 --> 00:01:03,490 Now if we wanted to perhaps change that let's say my relationship status all of a sudden goes from single 13 00:01:03,490 --> 00:01:05,020 to It's complicated. 14 00:01:05,590 --> 00:01:07,560 Well that's an easy fix. 15 00:01:07,600 --> 00:01:12,650 We would just do relationship status equals to. 16 00:01:12,820 --> 00:01:15,470 It's complicated. 17 00:01:15,470 --> 00:01:20,710 I remember because of the single quote we'll have to do backslash 18 00:01:24,450 --> 00:01:27,620 it's complicated. 19 00:01:27,850 --> 00:01:35,420 And now if I print my relationship status you'll see that it's been updated to It's complicated. 20 00:01:35,420 --> 00:01:36,750 I am no longer single. 21 00:01:36,830 --> 00:01:40,980 Hooray but this is pretty simple. 22 00:01:40,990 --> 00:01:45,310 Let's do something more complicated and this is going to be a fun exercise. 23 00:01:45,310 --> 00:01:56,630 Let's create a program that guesses your age let's use the input method that we've seen before. 24 00:01:56,930 --> 00:02:05,560 Remember the input method allows us to type something in here and receive it as input so we can assign 25 00:02:05,560 --> 00:02:06,610 that to a variable. 26 00:02:06,640 --> 00:02:16,570 So let's say this variable is going to be birth year and that's going to equal the input that's going 27 00:02:16,570 --> 00:02:22,630 to ask when or what year where you 28 00:02:28,640 --> 00:02:30,000 now from here. 29 00:02:30,110 --> 00:02:34,690 I want you to pause the video and try to solve this yourself. 30 00:02:34,760 --> 00:02:40,940 How can you make it so that at the end of this program you're going to get asked what year where you're 31 00:02:40,940 --> 00:02:48,080 born you're going to type in your ear and then it's going to print out your age is whatever the ages. 32 00:02:48,830 --> 00:02:50,070 So positive video. 33 00:02:50,210 --> 00:02:54,680 Try and solve this on your own mind you there is a bit of a trick in here. 34 00:02:54,680 --> 00:03:01,700 So if you get stuck try to google around and figure out what the issue may be. 35 00:03:01,700 --> 00:03:09,550 Again part of being a programmer is trying to solve these problems that you don't know the answers to. 36 00:03:09,550 --> 00:03:12,570 All right let me show you my solution. 37 00:03:12,590 --> 00:03:19,590 We have our birth year here that we're going to store in a variable and now we're going to calculate 38 00:03:19,590 --> 00:03:30,420 the h I'm going to say H equals Well it's going to equal the current year let's say 20 19 and then 20 39 00:03:30,420 --> 00:03:38,970 19 here is going to get subtracted from whatever the birth year that you entered. 40 00:03:39,750 --> 00:03:51,300 So let's enter that and then we're simply going to say print your age is and we want to use an F string 41 00:03:51,300 --> 00:03:52,000 here. 42 00:03:52,020 --> 00:03:58,010 So I'm going to add an F here and then simply say 43 00:04:02,740 --> 00:04:08,050 if I run this I get what year were you born. 44 00:04:08,100 --> 00:04:12,030 I was born in nineteen eighty six. 45 00:04:12,070 --> 00:04:13,080 Hmm. 46 00:04:13,120 --> 00:04:21,160 We get an error and if you try this yourself you may have encountered this air we get something called 47 00:04:21,340 --> 00:04:26,590 a Type here and there's lots of errors that you can get in Python. 48 00:04:26,590 --> 00:04:32,410 Again we have a section on air so don't stress too much about it but if you read here it says unsupported 49 00:04:32,530 --> 00:04:40,850 operant type has for minus int and string. 50 00:04:41,390 --> 00:04:44,280 Let's try and debug this. 51 00:04:44,300 --> 00:04:49,580 It looks like we're using minus on an integer and a string. 52 00:04:49,580 --> 00:04:52,800 So let me print out here. 53 00:04:53,120 --> 00:05:06,530 The type of birth year if I run this and let's enter in nineteen eighty six I get class String and this 54 00:05:06,530 --> 00:05:15,350 is a little gotcha because what input does is it asks you for an input but that input that I wrote 1 55 00:05:15,350 --> 00:05:16,750 9 8 6. 56 00:05:16,750 --> 00:05:23,610 Well that actually gets converted to a string and assigned to birth year. 57 00:05:23,620 --> 00:05:33,490 So what that means is that we're trying to subtract a number or a string from a number. 58 00:05:33,600 --> 00:05:42,350 So how do we solve this issue well you'd have to turn this into an integer and this is something that 59 00:05:42,350 --> 00:05:52,130 we saw previously what we need to do is to convert this into an integer with using the int function 60 00:05:53,350 --> 00:06:05,440 so let's try that if I remove this and click Run I'll say 1986 and look at that. 61 00:06:05,680 --> 00:06:13,630 Your age is 33 we've created a program that was able to tell your age based on that year that you were 62 00:06:13,630 --> 00:06:14,860 born. 63 00:06:14,860 --> 00:06:22,450 Now this may have been tricky to you but it teaches an important concept in programming that is sometimes 64 00:06:22,450 --> 00:06:30,490 you storing data into different data types and sometimes you need those different data types to interact 65 00:06:30,760 --> 00:06:34,810 together so you'll see a lot of problems. 66 00:06:34,880 --> 00:06:41,390 Well you have to convert a data type and this is a very common one where you take an input that's a 67 00:06:41,390 --> 00:06:49,530 string and then you convert it to something like an integer so you can perform a mathematical operation. 68 00:06:49,530 --> 00:06:55,110 And that's why if you remember we gave you a list of all our data types in Python. 69 00:06:55,110 --> 00:07:00,930 The fundamental data types and all of them were blue because well each one of these our actions are 70 00:07:00,930 --> 00:07:04,230 functions that we can use. 71 00:07:04,310 --> 00:07:13,160 For example I converted the birth year into integer but I could have also converted this to a float 72 00:07:13,400 --> 00:07:21,920 for example and if I run this it would still work because Python knows that well we can use integers 73 00:07:21,950 --> 00:07:27,380 and floats in mathematical operation but you can see here that it's converted into a float. 74 00:07:27,380 --> 00:07:33,210 Now if we convert this into a boolean and I click Run 75 00:07:36,470 --> 00:07:40,990 Your age is twenty eighteen that's really confusing right. 76 00:07:41,000 --> 00:07:45,920 Well that's because this gets turned into true. 77 00:07:46,160 --> 00:07:54,060 And underneath the hood Python does something weird where a true value is converted to one because boolean. 78 00:07:54,110 --> 00:07:58,040 Remember it's 1 or 0 true or false. 79 00:07:58,040 --> 00:07:58,530 All right. 80 00:07:58,610 --> 00:08:00,850 Hopefully this didn't confuse you too much. 81 00:08:00,860 --> 00:08:03,070 It's something that will encounter throughout the course. 82 00:08:03,110 --> 00:08:05,920 Don't worry we'll get more and more practice. 83 00:08:06,140 --> 00:08:11,540 However I hope you get to practice this a little bit to really understand what's going on because although 84 00:08:11,540 --> 00:08:18,020 this is a couple of lines of code the principles that we use here we're going to use throughout bigger 85 00:08:18,020 --> 00:08:22,390 and bigger code bases so I guess I'll see in the next one by. 8782

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