All language subtitles for 012 Decision Making in Python_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
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 Download
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,840 --> 00:00:06,420 Now that we are happy with the way the code looks, we're ready to add more features to the program. 2 00:00:06,960 --> 00:00:13,740 One thing that I need is very important, and that the program is lacking is checking if the user is 3 00:00:13,740 --> 00:00:17,490 actually inputting all the required arguments. 4 00:00:17,700 --> 00:00:23,730 So we know that the program will not work if the user does not input an interface or a new Mac. 5 00:00:24,000 --> 00:00:30,720 But if someone goes to the terminal and for example, runs the program by saying mac changer, I had 6 00:00:30,720 --> 00:00:37,080 zero and not give a mac, you'll see that python will just throw an error. 7 00:00:37,500 --> 00:00:43,710 Now to us, this is useful as a programmer, but to the user this is not nice at all. 8 00:00:43,740 --> 00:00:49,950 We want to display a meaningful error to the user telling them that you forgot to give us a mac address. 9 00:00:49,950 --> 00:00:52,350 Please make sure you input a mac address. 10 00:00:52,980 --> 00:00:59,160 Now, in order to do this, we need to implement some decision making in our program. 11 00:00:59,340 --> 00:01:06,270 We need a way to check and make sure that the user entered a value for the interface and also entered 12 00:01:06,270 --> 00:01:07,800 a value for the Mac. 13 00:01:08,070 --> 00:01:11,700 To do this, we'll need to use an if statement. 14 00:01:12,030 --> 00:01:18,180 So in this lecture we're going to have an introduction on what if statements is what decision making 15 00:01:18,180 --> 00:01:22,530 is, and in the next lecture will implement it in our program. 16 00:01:23,990 --> 00:01:31,550 Now when we talk about decision making or if statements, we're talking about executing code only if 17 00:01:31,550 --> 00:01:33,140 a condition is true. 18 00:01:33,590 --> 00:01:40,670 So we're going to first check if the user entered a value for a mac address and only print an error 19 00:01:40,670 --> 00:01:44,450 message if the user did not enter a mac address. 20 00:01:44,450 --> 00:01:48,290 So we're only executing code based on a condition. 21 00:01:48,620 --> 00:01:51,500 Now there are lots of ways to come up with conditions. 22 00:01:51,500 --> 00:01:54,530 You can check if a variable is equal to something. 23 00:01:54,530 --> 00:01:57,260 You can check if something is greater smaller. 24 00:01:57,260 --> 00:02:00,440 You can check if a variable exists in the list. 25 00:02:00,440 --> 00:02:04,010 You can check if something is true or false, and so on. 26 00:02:04,640 --> 00:02:09,380 As we go through the course, we're going to be using a lot of conditional statements, and all of this 27 00:02:09,380 --> 00:02:12,500 is going to become very clear to you right now. 28 00:02:12,500 --> 00:02:19,520 I just want to give you a general idea of what decision making is and some basic examples of if statements. 29 00:02:19,520 --> 00:02:24,110 And as we go through the course, we're actually going to be using all of these statements, we're going 30 00:02:24,110 --> 00:02:25,880 to be using lots of these conditions. 31 00:02:25,880 --> 00:02:29,810 And everything is going to become clear to you by the end of the course. 32 00:02:31,440 --> 00:02:32,100 Right now. 33 00:02:32,100 --> 00:02:38,070 I just wanted to have a quick comparison between three common ways of writing an F statement. 34 00:02:38,490 --> 00:02:43,530 So here on the left, we have the most basic example of an F statement. 35 00:02:43,860 --> 00:02:46,020 So we do if condition. 36 00:02:46,020 --> 00:02:50,800 And like I said, a condition can be a lot of different things and we'll have a look on them later on. 37 00:02:50,820 --> 00:02:53,460 So let's just think of a condition as is. 38 00:02:53,910 --> 00:02:58,860 So we're doing F condition and then we have a block of code here. 39 00:02:59,040 --> 00:03:04,800 And this block of code will only be executed if this condition is true. 40 00:03:05,370 --> 00:03:12,600 Else we have another block of code and this block of code will only be executed if the above condition 41 00:03:12,600 --> 00:03:13,470 is false. 42 00:03:13,500 --> 00:03:18,140 So when you run a Python program in this example, it will check for the condition. 43 00:03:18,150 --> 00:03:20,950 If it's true, it will execute the code here. 44 00:03:20,970 --> 00:03:25,230 If it's false, it will execute the code in the false block. 45 00:03:25,770 --> 00:03:32,040 Then, once it's done with this, whether it did the code in the F block or in the else block, it will 46 00:03:32,040 --> 00:03:35,940 continue with the rest of the code executing it line by line. 47 00:03:36,660 --> 00:03:40,440 Another example is where we have multiple conditions. 48 00:03:40,440 --> 00:03:45,960 So in this example we only had one condition we had if condition otherwise do this. 49 00:03:46,710 --> 00:03:55,140 In this example we can do if condition one, we execute the code in condition one or if condition one 50 00:03:55,140 --> 00:03:59,480 is false, then we're going to check is condition two is true. 51 00:03:59,550 --> 00:04:06,600 If it is, then execute the code here and you can keep doing this on and on and on and on. 52 00:04:06,840 --> 00:04:14,700 Finally, you can use an LS statement to execute code if all of the above conditions are false. 53 00:04:15,730 --> 00:04:17,890 So let's go over this one more time. 54 00:04:18,220 --> 00:04:21,670 In the statement, we have multiple conditions. 55 00:04:22,150 --> 00:04:24,850 It will first check the first condition. 56 00:04:25,030 --> 00:04:32,000 If it's true, it will execute the code in the first condition block and it will exit everything else. 57 00:04:32,020 --> 00:04:36,400 It won't check any of this, and it will go directly to the rest of the code. 58 00:04:37,120 --> 00:04:41,710 If condition one is false, it will check its condition two true. 59 00:04:41,920 --> 00:04:45,580 If it is, it will execute the code here and exit. 60 00:04:45,580 --> 00:04:47,320 Go to the rest of the code. 61 00:04:48,070 --> 00:04:54,820 If all of the conditions are false, it will execute the code in the statement and then go to the rest 62 00:04:54,820 --> 00:04:55,780 of the code. 63 00:04:56,020 --> 00:05:02,560 So this is an example of using multiple conditions in one single if statement. 64 00:05:03,830 --> 00:05:10,010 This example brings me to the third example, which a lot of people get these two mixed up, and that's 65 00:05:10,010 --> 00:05:12,290 why I wanted to have them side by side. 66 00:05:12,320 --> 00:05:18,740 I usually like to teach you programming as a program, but I wanted to have these examples here because 67 00:05:18,740 --> 00:05:23,360 a lot of people get confused with this, and I want to make sure that you understand the difference 68 00:05:23,900 --> 00:05:25,010 in this example. 69 00:05:25,010 --> 00:05:28,370 And here we have multiple conditions as well. 70 00:05:28,640 --> 00:05:33,200 But notice we have two separate if statements. 71 00:05:33,230 --> 00:05:35,600 This is different than what we have here. 72 00:05:35,600 --> 00:05:39,550 We have an if, we have an LF and we have an LS. 73 00:05:39,560 --> 00:05:44,360 So all of this is one if statement in here. 74 00:05:44,360 --> 00:05:46,730 This is two separate if statements. 75 00:05:46,850 --> 00:05:50,210 So what happens is python checks for condition one. 76 00:05:50,240 --> 00:05:52,880 If it's true, it executes the code here. 77 00:05:53,750 --> 00:05:59,900 Even if it's true and it executes the code here, it will check condition two and if it's true, it 78 00:05:59,900 --> 00:06:02,840 will execute the code and condition two as well. 79 00:06:03,350 --> 00:06:10,580 So unlike this example, if condition one is true, Python will go to the rest of the code directly 80 00:06:10,580 --> 00:06:13,340 and want check for the rest of the conditions. 81 00:06:13,490 --> 00:06:17,150 Whereas in here these are two separate if statements. 82 00:06:17,150 --> 00:06:20,900 So if condition one is true, the code here will be executed. 83 00:06:20,900 --> 00:06:24,620 If condition two is true, the code here will be executed as well. 84 00:06:25,070 --> 00:06:27,830 You can also use ls ifs in here. 85 00:06:27,830 --> 00:06:29,450 You can use ls with them. 86 00:06:29,720 --> 00:06:34,370 The reason behind this is these are two separate if statements. 87 00:06:36,010 --> 00:06:36,340 Now. 88 00:06:36,340 --> 00:06:37,230 That's it for now. 89 00:06:37,240 --> 00:06:38,890 I don't want to make this too long. 90 00:06:38,920 --> 00:06:44,770 I just wanted to have these three examples of if statements in here so that you understand the difference 91 00:06:44,770 --> 00:06:45,700 between them. 92 00:06:45,700 --> 00:06:50,950 And in the next lecture, we're actually going to be implementing only one example because it makes 93 00:06:50,950 --> 00:06:53,170 sense in our case and we'll see why. 9440

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