Hello and welcome to this lecture in this lecture we're going to learn about if else statement.
So decision making is really important concept if you want to this navigate to the sort portion of a
chord.
And if you want to execute that based on the condition that is to be satisfied.
So let's see how this feels work.
So the basic condition over here is if certain condition is performed or basically a certain condition
is true then certain portion of the work or certain code will be executed.
Otherwise it won't work.
So the flow will be going or navigating from one side to another based on that decision.
So we have already learned how to make the logic which is basically by the comparison operator we have
made the logic like three is greater than five.
If this is true which is obviously false this is false.
That means we are making the condition over here.
So if it is true then certain person will work.
So something like if if three is greater than five certain person will be this person or this court
will be executed or are.
This court will be executed that is inside here or this court will be executed.
So something like this is a condition if this is true this poor portion of court will work if if it
is if 9 is greater than 0 if this is the condition then this part of God will work or this part will
of God will work.
So this is basically a condition or a decision making.
So let's make a less clear to one program to see this if else work in the python or not.
So first of all let's see the syntax.
So first of all you see if which is all in lowercase.
So this is to start with the condition and you pass the condition inside these panties.
So I'll just say condition and you give this call in here.
And after that you pass the code that is to be executed inside.
Here is which is basically if this condition is false.
Else part will work.
That means the code inside this ls will work.
So let's see the condition now are basically let's create one program to see.
So let's create a program to check if the number is positive or negative so let's see that.
So first of all instead of just giving the number let's see number and input that number from the user.
So I'll see into your number for the user in this is the masses for the user.
And I'll just say enter this and the next thing is too sick.
So I'll just say if number is.
So if we see here in this input you should get some idea that I have already told in the previous lecture
but I'll just put the here on notice for you because we'll see how this either will be executed or basically
how we'll get either from here in the minute but let's make a condition right now.
So.
What I just did.
So the same number is greater than zero which is basically the positive since we just get the condition
that is positive.
So I'll just say print number or you can also format it.
So I'll just say format is positive and we know how to format using this format matter.
And this past year the number that is in doubt from the user.
So let's close this print statement as if it is the case which is the negative case.
So I would say is negative and this format and this this string is in the same number that is interpreted
the user.
Let's see if this works on auto users get the basic idea we're just making the condition here taking
the number from the user anyway taking with this condition which is the comparison operator saying that
if it is greater than zero which is basically the positive number we have formatting here that number
is positive.
Basically no memories have value.
Value is positive as value will be negative.
A simple logical where let's say this but this is not going to work.
Let's see how this is not going to.
So first of all into your number 76.
If I say gymnastics press into it is saying these comparison operator is not supported between instances
of string and integer.
So what does that mean.
Because you are seeing here that this part is getting either why that is getting data because we are
just comparing here the number which is a string with these zero.
So I've already told you before that if you see if you go over here and if users input anything from
the user let me say the name or basically is OK and if I say input and if I input something like say
sixty seven and if you see that type of this is it is not going to be the integer it is going to be
this string.
So what we just did here was we just compared this string that is the number into our from the user
with the zero which is the into though so we cannot compare a string with an integer.
So we have to convert this string which is interred but it will be entered as a number but that will
be converted to this string by this input method.
So let's convert this first into the integer which is by this intimate or this converted first and let's
see if this works or not so let's save this first place year five.
Now list into the number let's say negative of two.
Let's sit it into and negative two is negative.
Obviously it is negative.
So let's do one more time.
Let's save this place a five.
Let's see six which is positive.
So six is positive.
Let's save this again precept five.
And if I hit zero again saying zero is negative.
So zero is not negative zero is basically zero.
It is the neutral number but it is giving us zero is negative.
We have to have another condition now.
So what we are doing here is we are just taking for the zero if it is good or zero or if it is not but
we're not taking.
If it is equal to zero no that means we have to put another condition over here which can be done with
this Elif.
It is different from other programming language so normally we put here elusive.
But in the case of Python it should be Elif.
Otherwise it is not going to be run.
So this plus Elif and now I'll say no that is inter from the user is equal equal zero.
If it is the case what you are going to do with to.
Simply
number is zero.
No need to format the save this special five.
Let's see if this works it is positive.
Let's see.
Let's press a fireplace.
Zero again in memory zero now.
So we are just adding another condition to make the decisions.
So if elses statement is a conditional statement that is going to execute the part of accord based on
the decisions are based on the conditions that it has met or not.
If this part is true this call will be executed.
You can do different thing over here.
You can print hey you can print everything.
Anything will be executed over here
anything you pass here will be executed by save this press 5.
If I just give the positive number you can see the cord inside that Phil has been executed.
Six is positive cool and everything has been printed.
That means if this condition is made this part of cord will be executed.
And all the part which is after this won't be executed because it is just giving us the flow control
based on these conditions.
So this is the important conditional statement in the next lecture will is learn about the looping which
is then Northern flow control method soon the next to.