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

Original subtitles

Welcome back.

So up until now we've learned about integers floats strings and volume values.

So let's try and tie some of those things together.

Let's imagine you are Facebook.

How do you think Facebook works.

Underneath the hood when it comes to your profile well would have let's say a variable called name.

And this will have your name and then they'll probably have a variable with your age.

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

say relationship status.

So again we also have relationship status on Facebook.

And for now let's say single so that's my Facebook profile right there.

Now if we wanted to perhaps change that let's say my relationship status all of a sudden goes from single

to It's complicated.

Well that's an easy fix.

We would just do relationship status equals to.

It's complicated.

I remember because of the single quote we'll have to do backslash

it's complicated.

And now if I print my relationship status you'll see that it's been updated to It's complicated.

I am no longer single.

Hooray but this is pretty simple.

Let's do something more complicated and this is going to be a fun exercise.

Let's create a program that guesses your age let's use the input method that we've seen before.

Remember the input method allows us to type something in here and receive it as input so we can assign

that to a variable.

So let's say this variable is going to be birth year and that's going to equal the input that's going

to ask when or what year where you

now from here.

I want you to pause the video and try to solve this yourself.

How can you make it so that at the end of this program you're going to get asked what year where you're

born you're going to type in your ear and then it's going to print out your age is whatever the ages.

So positive video.

Try and solve this on your own mind you there is a bit of a trick in here.

So if you get stuck try to google around and figure out what the issue may be.

Again part of being a programmer is trying to solve these problems that you don't know the answers to.

All right let me show you my solution.

We have our birth year here that we're going to store in a variable and now we're going to calculate

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

19 here is going to get subtracted from whatever the birth year that you entered.

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

here.

So I'm going to add an F here and then simply say

if I run this I get what year were you born.

I was born in nineteen eighty six.

Hmm.

We get an error and if you try this yourself you may have encountered this air we get something called

a Type here and there's lots of errors that you can get in Python.

Again we have a section on air so don't stress too much about it but if you read here it says unsupported

operant type has for minus int and string.

Let's try and debug this.

It looks like we're using minus on an integer and a string.

So let me print out here.

The type of birth year if I run this and let's enter in nineteen eighty six I get class String and this

is a little gotcha because what input does is it asks you for an input but that input that I wrote 1

9 8 6.

Well that actually gets converted to a string and assigned to birth year.

So what that means is that we're trying to subtract a number or a string from a number.

So how do we solve this issue well you'd have to turn this into an integer and this is something that

we saw previously what we need to do is to convert this into an integer with using the int function

so let's try that if I remove this and click Run I'll say 1986 and look at that.

Your age is 33 we've created a program that was able to tell your age based on that year that you were

born.

Now this may have been tricky to you but it teaches an important concept in programming that is sometimes

you storing data into different data types and sometimes you need those different data types to interact

together so you'll see a lot of problems.

Well you have to convert a data type and this is a very common one where you take an input that's a

string and then you convert it to something like an integer so you can perform a mathematical operation.

And that's why if you remember we gave you a list of all our data types in Python.

The fundamental data types and all of them were blue because well each one of these our actions are

functions that we can use.

For example I converted the birth year into integer but I could have also converted this to a float

for example and if I run this it would still work because Python knows that well we can use integers

and floats in mathematical operation but you can see here that it's converted into a float.

Now if we convert this into a boolean and I click Run

Your age is twenty eighteen that's really confusing right.

Well that's because this gets turned into true.

And underneath the hood Python does something weird where a true value is converted to one because boolean.

Remember it's 1 or 0 true or false.

All right.

Hopefully this didn't confuse you too much.

It's something that will encounter throughout the course.

Don't worry we'll get more and more practice.

However I hope you get to practice this a little bit to really understand what's going on because although

this is a couple of lines of code the principles that we use here we're going to use throughout bigger

and bigger code bases so I guess I'll see in the next one by.

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