All language subtitles for 019 [Interactive Coding Exercise] Data Types.en_US

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic Download
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
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

All right, now

it's time to put what you've learned into practice by clicking on the data types

day 2.1 code challenge.

In this challenge,

the idea is that you are going to be given a random two-digit number,

so something like 39, and your code that you'll write

will be able to add the first digit to the second digit and end up with a

numerical result. So for example, if the input was 39,

then 3 + 9 would be equal to 12. So the output would be 12.

And if the input was 26,

then your code needs to print 8 to the console.

So you're going to need to think about type checking, type conversion,

as well as everything that you learned before.

And then you're going to write your code below this line without changing any of

these lines. So pause the video now and give this code challenge a go.

All right. So how did that go? Did you manage to do it? If not,

have a cup of tea or give yourself a little bit of a break,

think about something else and then come back to it and try it again.

If you've already

given it a good go and you want to see what the solution might be,

then follow along with me.

So the first thing we know is that we're going to have a variable

that's going to be equal to a two-digit number.

But remember that that could mean anything. That could mean an integer,

that could mean a floating-point number, that could even mean a number as a

string.

So it might be helpful to actually find out the data type of this two-digit

number that we get. And to do that, we of course use the type function, all

lowercase. And then in between the parentheses,

we add the thing that we want to check. So it's this variable.

And then let's go ahead and print the result into the console.

So now let's run our code and let's type a two-digit number,

say 56.

and we get the result that the type of this two-digit number is a string

because, of course, we're getting hold of this through the input function and the

user could be typing anything into this input, a string,

their name or a number.

So now that we know that this variable has the datatype string,

then you can think of a little bit about what we know we can do with strings.

We can subscript strings, right? So if we had a string like hello,

and we want it to get a hold of the first character, we could put zero there.

And when I print this,

we'll get H being selected out of this string.

So if we know that we can subscript strings to get a hold of a particular value

at a particular position just by using subscripting like this,

then we can do the same with our two-digit number.

So we could say two_digit_number, let's get hold of the first digit.

So let's call it

first_digit equals two_digit_number [

0],

and then the second_digit could be two_digit_number [1].

Now,

when I go ahead and print these two items,

first_digit and second_digit,

then you'll see that if I enter a number like 87,

then my first digit is 8 and my second digit is 7.

So now I can probably start thinking about adding those two digits together.

For example,

we can say that result equals first_digit plus second_digit.

But of course, when I run this right now and I print the value of result,

you'll see that for a number like 87

what I will get is just a eight concatenated to seven,

which turns it back into 87, which is not what I want at all.

Especially after all of my hard work separating out the digits.

What I want to do instead is to turn each of these,

which currently has the data type of string,

so I can demonstrate that to you by saying type of first_digit,

you can see it is a string.

So if I could only change first_digit and second_digit from string data types

into an integer data type by using the type conversion that we learned about

in the last lesson, well then once I do that,

then this plus sign has a whole different meaning because now it's going to add

this first_digit to the second_digit instead of concatenating it.

So now if I go ahead and print the results,

then you'll see that for the same number

87, my result is now 15.

I've now managed to achieve what the code exercise wants me to do.

So did you manage to get it right? If not,

go ahead and have a look at the model solution

and I've written some comments for each line of code that walks you through each

of the steps.

Now notice that instead of converting the second_digit here,

you can also do it up here, like what you see right here.

So I have a play around with the code,

especially if you struggled with this and didn't manage to get it right.

And then once you've understood what's going on here line by line,

if you need, have a look at the previous videos,

then go back to the code challenge and attempt it again.

And only once you're happy that you really understand everything that was

covered in this challenge,

then head over to the next lesson where we're going to talk more about

mathematical operators

like the plus sign and others that you can use in your code. So for all of that

and more, I'll see you on the next lesson.

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