Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
Now that we are happy with the way the code looks, we're ready to add more features to the program.
One thing that I need is very important, and that the program is lacking is checking if the user is
actually inputting all the required arguments.
So we know that the program will not work if the user does not input an interface or a new Mac.
But if someone goes to the terminal and for example, runs the program by saying mac changer, I had
zero and not give a mac, you'll see that python will just throw an error.
Now to us, this is useful as a programmer, but to the user this is not nice at all.
We want to display a meaningful error to the user telling them that you forgot to give us a mac address.
Please make sure you input a mac address.
Now, in order to do this, we need to implement some decision making in our program.
We need a way to check and make sure that the user entered a value for the interface and also entered
a value for the Mac.
To do this, we'll need to use an if statement.
So in this lecture we're going to have an introduction on what if statements is what decision making
is, and in the next lecture will implement it in our program.
Now when we talk about decision making or if statements, we're talking about executing code only if
a condition is true.
So we're going to first check if the user entered a value for a mac address and only print an error
message if the user did not enter a mac address.
So we're only executing code based on a condition.
Now there are lots of ways to come up with conditions.
You can check if a variable is equal to something.
You can check if something is greater smaller.
You can check if a variable exists in the list.
You can check if something is true or false, and so on.
As we go through the course, we're going to be using a lot of conditional statements, and all of this
is going to become very clear to you right now.
I just want to give you a general idea of what decision making is and some basic examples of if statements.
And as we go through the course, we're actually going to be using all of these statements, we're going
to be using lots of these conditions.
And everything is going to become clear to you by the end of the course.
Right now.
I just wanted to have a quick comparison between three common ways of writing an F statement.
So here on the left, we have the most basic example of an F statement.
So we do if condition.
And like I said, a condition can be a lot of different things and we'll have a look on them later on.
So let's just think of a condition as is.
So we're doing F condition and then we have a block of code here.
And this block of code will only be executed if this condition is true.
Else we have another block of code and this block of code will only be executed if the above condition
is false.
So when you run a Python program in this example, it will check for the condition.
If it's true, it will execute the code here.
If it's false, it will execute the code in the false block.
Then, once it's done with this, whether it did the code in the F block or in the else block, it will
continue with the rest of the code executing it line by line.
Another example is where we have multiple conditions.
So in this example we only had one condition we had if condition otherwise do this.
In this example we can do if condition one, we execute the code in condition one or if condition one
is false, then we're going to check is condition two is true.
If it is, then execute the code here and you can keep doing this on and on and on and on.
Finally, you can use an LS statement to execute code if all of the above conditions are false.
So let's go over this one more time.
In the statement, we have multiple conditions.
It will first check the first condition.
If it's true, it will execute the code in the first condition block and it will exit everything else.
It won't check any of this, and it will go directly to the rest of the code.
If condition one is false, it will check its condition two true.
If it is, it will execute the code here and exit.
Go to the rest of the code.
If all of the conditions are false, it will execute the code in the statement and then go to the rest
of the code.
So this is an example of using multiple conditions in one single if statement.
This example brings me to the third example, which a lot of people get these two mixed up, and that's
why I wanted to have them side by side.
I usually like to teach you programming as a program, but I wanted to have these examples here because
a lot of people get confused with this, and I want to make sure that you understand the difference
in this example.
And here we have multiple conditions as well.
But notice we have two separate if statements.
This is different than what we have here.
We have an if, we have an LF and we have an LS.
So all of this is one if statement in here.
This is two separate if statements.
So what happens is python checks for condition one.
If it's true, it executes the code here.
Even if it's true and it executes the code here, it will check condition two and if it's true, it
will execute the code and condition two as well.
So unlike this example, if condition one is true, Python will go to the rest of the code directly
and want check for the rest of the conditions.
Whereas in here these are two separate if statements.
So if condition one is true, the code here will be executed.
If condition two is true, the code here will be executed as well.
You can also use ls ifs in here.
You can use ls with them.
The reason behind this is these are two separate if statements.
Now.
That's it for now.
I don't want to make this too long.
I just wanted to have these three examples of if statements in here so that you understand the difference
between them.
And in the next lecture, we're actually going to be implementing only one example because it makes
sense in our case and we'll see why.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.