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

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
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
tl Filipino
fi Finnish
fr French Download
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,180 --> 00:00:00,810 All right, now 2 00:00:00,810 --> 00:00:05,280 it's time to put what you've learned into practice by clicking on the data types 3 00:00:05,400 --> 00:00:08,040 day 2.1 code challenge. 4 00:00:09,540 --> 00:00:10,470 In this challenge, 5 00:00:10,500 --> 00:00:15,450 the idea is that you are going to be given a random two-digit number, 6 00:00:15,480 --> 00:00:20,480 so something like 39, and your code that you'll write 7 00:00:21,060 --> 00:00:26,060 will be able to add the first digit to the second digit and end up with a 8 00:00:26,850 --> 00:00:31,650 numerical result. So for example, if the input was 39, 9 00:00:31,680 --> 00:00:36,000 then 3 + 9 would be equal to 12. So the output would be 12. 10 00:00:36,480 --> 00:00:39,060 And if the input was 26, 11 00:00:39,180 --> 00:00:42,420 then your code needs to print 8 to the console. 12 00:00:43,080 --> 00:00:47,100 So you're going to need to think about type checking, type conversion, 13 00:00:47,430 --> 00:00:49,710 as well as everything that you learned before. 14 00:00:50,550 --> 00:00:54,270 And then you're going to write your code below this line without changing any of 15 00:00:54,270 --> 00:00:58,140 these lines. So pause the video now and give this code challenge a go. 16 00:01:02,610 --> 00:01:07,200 All right. So how did that go? Did you manage to do it? If not, 17 00:01:07,380 --> 00:01:09,900 have a cup of tea or give yourself a little bit of a break, 18 00:01:09,900 --> 00:01:12,750 think about something else and then come back to it and try it again. 19 00:01:13,530 --> 00:01:14,110 If you've already 20 00:01:14,110 --> 00:01:17,340 given it a good go and you want to see what the solution might be, 21 00:01:17,700 --> 00:01:18,900 then follow along with me. 22 00:01:19,650 --> 00:01:23,250 So the first thing we know is that we're going to have a variable 23 00:01:23,280 --> 00:01:26,970 that's going to be equal to a two-digit number. 24 00:01:27,540 --> 00:01:30,660 But remember that that could mean anything. That could mean an integer, 25 00:01:30,660 --> 00:01:34,590 that could mean a floating-point number, that could even mean a number as a 26 00:01:34,590 --> 00:01:35,423 string. 27 00:01:35,790 --> 00:01:40,790 So it might be helpful to actually find out the data type of this two-digit 28 00:01:41,310 --> 00:01:46,200 number that we get. And to do that, we of course use the type function, all 29 00:01:46,200 --> 00:01:48,810 lowercase. And then in between the parentheses, 30 00:01:48,840 --> 00:01:52,470 we add the thing that we want to check. So it's this variable. 31 00:01:53,040 --> 00:01:56,130 And then let's go ahead and print the result into the console. 32 00:01:56,550 --> 00:02:00,390 So now let's run our code and let's type a two-digit number, 33 00:02:00,570 --> 00:02:01,590 say 56. 34 00:02:02,100 --> 00:02:07,100 and we get the result that the type of this two-digit number is a string 35 00:02:08,670 --> 00:02:13,410 because, of course, we're getting hold of this through the input function and the 36 00:02:13,410 --> 00:02:17,280 user could be typing anything into this input, a string, 37 00:02:17,310 --> 00:02:18,840 their name or a number. 38 00:02:19,290 --> 00:02:22,560 So now that we know that this variable has the datatype string, 39 00:02:22,950 --> 00:02:27,090 then you can think of a little bit about what we know we can do with strings. 40 00:02:27,330 --> 00:02:31,920 We can subscript strings, right? So if we had a string like hello, 41 00:02:32,250 --> 00:02:36,330 and we want it to get a hold of the first character, we could put zero there. 42 00:02:36,570 --> 00:02:37,860 And when I print this, 43 00:02:38,160 --> 00:02:42,120 we'll get H being selected out of this string. 44 00:02:43,050 --> 00:02:48,050 So if we know that we can subscript strings to get a hold of a particular value 45 00:02:50,130 --> 00:02:54,690 at a particular position just by using subscripting like this, 46 00:02:54,990 --> 00:02:58,020 then we can do the same with our two-digit number. 47 00:02:58,230 --> 00:03:02,950 So we could say two_digit_number, let's get hold of the first digit. 48 00:03:03,130 --> 00:03:04,030 So let's call it 49 00:03:04,030 --> 00:03:08,830 first_digit equals two_digit_number [ 50 00:03:08,860 --> 00:03:09,693 0], 51 00:03:10,120 --> 00:03:15,120 and then the second_digit could be two_digit_number [1]. 52 00:03:16,660 --> 00:03:17,493 Now, 53 00:03:17,680 --> 00:03:22,180 when I go ahead and print these two items, 54 00:03:22,210 --> 00:03:25,990 first_digit and second_digit, 55 00:03:26,440 --> 00:03:30,280 then you'll see that if I enter a number like 87, 56 00:03:30,760 --> 00:03:34,600 then my first digit is 8 and my second digit is 7. 57 00:03:35,110 --> 00:03:39,820 So now I can probably start thinking about adding those two digits together. 58 00:03:40,420 --> 00:03:40,990 For example, 59 00:03:40,990 --> 00:03:45,990 we can say that result equals first_digit plus second_digit. 60 00:03:47,200 --> 00:03:51,790 But of course, when I run this right now and I print the value of result, 61 00:03:52,270 --> 00:03:54,910 you'll see that for a number like 87 62 00:03:55,390 --> 00:04:00,340 what I will get is just a eight concatenated to seven, 63 00:04:00,520 --> 00:04:04,030 which turns it back into 87, which is not what I want at all. 64 00:04:04,390 --> 00:04:07,840 Especially after all of my hard work separating out the digits. 65 00:04:08,470 --> 00:04:11,770 What I want to do instead is to turn each of these, 66 00:04:12,070 --> 00:04:15,010 which currently has the data type of string, 67 00:04:15,190 --> 00:04:20,190 so I can demonstrate that to you by saying type of first_digit, 68 00:04:20,950 --> 00:04:24,460 you can see it is a string. 69 00:04:25,000 --> 00:04:30,000 So if I could only change first_digit and second_digit from string data types 70 00:04:31,000 --> 00:04:36,000 into an integer data type by using the type conversion that we learned about 71 00:04:37,240 --> 00:04:41,320 in the last lesson, well then once I do that, 72 00:04:41,350 --> 00:04:46,120 then this plus sign has a whole different meaning because now it's going to add 73 00:04:46,150 --> 00:04:50,260 this first_digit to the second_digit instead of concatenating it. 74 00:04:50,620 --> 00:04:53,350 So now if I go ahead and print the results, 75 00:04:55,420 --> 00:04:58,270 then you'll see that for the same number 76 00:04:59,770 --> 00:05:02,500 87, my result is now 15. 77 00:05:03,310 --> 00:05:08,140 I've now managed to achieve what the code exercise wants me to do. 78 00:05:09,560 --> 00:05:12,190 So did you manage to get it right? If not, 79 00:05:12,220 --> 00:05:15,340 go ahead and have a look at the model solution 80 00:05:15,610 --> 00:05:19,990 and I've written some comments for each line of code that walks you through each 81 00:05:19,990 --> 00:05:20,823 of the steps. 82 00:05:21,070 --> 00:05:25,930 Now notice that instead of converting the second_digit here, 83 00:05:26,380 --> 00:05:30,250 you can also do it up here, like what you see right here. 84 00:05:31,270 --> 00:05:32,950 So I have a play around with the code, 85 00:05:33,010 --> 00:05:36,520 especially if you struggled with this and didn't manage to get it right. 86 00:05:37,060 --> 00:05:40,660 And then once you've understood what's going on here line by line, 87 00:05:41,080 --> 00:05:43,300 if you need, have a look at the previous videos, 88 00:05:43,600 --> 00:05:46,390 then go back to the code challenge and attempt it again. 89 00:05:46,960 --> 00:05:50,260 And only once you're happy that you really understand everything that was 90 00:05:50,260 --> 00:05:51,610 covered in this challenge, 91 00:05:51,880 --> 00:05:54,910 then head over to the next lesson where we're going to talk more about 92 00:05:54,940 --> 00:05:56,290 mathematical operators 93 00:05:56,560 --> 00:06:01,540 like the plus sign and others that you can use in your code. So for all of that 94 00:06:01,660 --> 00:06:03,490 and more, I'll see you on the next lesson. 8916

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