0:00
Hey everyone, welcome back to our Python
0:02
journey. So this is module 3 and today
0:05
we are stepping into one of the most
0:08
powerful concepts in programming which
0:10
is making decisions using conditions.
0:14
So in this video we'll be exploring if
0:18
else decision structures. So in other
0:21
episodes we'll be going with the if l if
0:24
else decision structure and even python
0:26
nested if statements and then we will go
0:29
through the exercises.
0:31
Don't worry we are going to do it step
0:33
by step. So this video so in this
0:36
episode it will be all about if and else
0:44
let's start with if else decision
0:47
structure. So think of it like this like
0:50
you are giving your program a condition
0:53
to check based on whether that condition
0:56
is true or false. Like the program
0:58
decides which block of code to run. Like
1:04
I could say if it is raining
1:07
let's just think that if it is raining
1:11
then you'll carry an umbrella else you
1:14
won't. It's just simple.
1:17
So here is how it looks in Python.
1:23
if this is true, if this condition if it
1:26
is raining then you will carry the
1:29
umbrella. If not which is nothing but
1:33
you won't or maybe you'll just walk
1:36
without umbrella something like that. So
1:39
let me show you one more basic example.
1:41
If you see here like for example x value
1:44
is 7 and if x is less than 10. So if 7
1:51
is less than 10 then it is true. So then
1:55
it will just print whatever the code
1:58
that you write here. Else it will print
2:01
whatever like if it is if this condition
2:03
is false then it will print this. I hope
2:07
you are getting my point. So if
2:16
So now python will be thinking that what
2:17
is this x and what is its value? So
2:20
let's just give value of x = 7. Okay.
2:24
And if x = 7 then just print
2:55
Okay. So if x if x is less than 10 is
2:59
nothing but 7 is less than 10 then print
3:01
7 is less than 10. x is less than 10.
3:04
else exist 10 or more then it could be
3:07
equal to 10 or maybe greater than 10.
3:11
So here is how Python checks. I'm
3:14
repeating again is x less than 10 if yes
3:19
if it's true goes this line if not runs
3:25
this one. You can check.
3:32
See X is less than 10. And what if you
3:38
X is 10 or more. Just give 10.
3:44
X is 10 or more. See that's the
3:51
So this is the condition and this is the
3:53
code to execute and this is if keyword
3:57
and else keyword. So if is not met then
4:01
it will go to else. So this is what
4:06
and don't worry if and else must be
4:09
aligned properly with columns.
4:13
This is important. And also they must
4:16
follow the indentation because Python is
4:19
super picky about indentation. It
4:21
doesn't like if you don't give
4:22
indentation. You can just check like if
4:25
I do it immediately it will throw error
4:28
on my face. I didn't even execute it.
4:30
But if you see see there is something it
4:32
is expecting which is nothing but just a
4:38
Okay let's do more relatable one.
4:46
Like for example, age equal to 18.
4:53
age greater than or equal to 18,
5:03
you are of legal age.
5:23
So what's happening here? We have a
5:26
variable called age and its value is 80.
5:31
Then the if statement checks is age
5:33
greater than or equal to 18.
5:37
If yes, if it's true, then it will print
5:40
you are of legal age. Else you are
5:47
It's like this. You are standing at the
5:49
entrance of a movie theater and a guard
5:53
checks your ID. Okay? And if your age is
5:56
18 or more, then they will say come in.
5:59
Otherwise, sorry, you are too young. So
6:01
that is what maybe you are designing a
6:04
portal where you want to check the age
6:06
of a person whether the person have a
6:09
legal age or not. You know that there
6:11
are some rules that in most of the
6:15
like it could be Facebook or any other
6:17
social media accounts it will check the
6:19
age whether the person is above 18 or
6:22
not. So in the same way in order to
6:25
check that we need this if else
6:27
statements. So that is how if else works
6:31
in Python. It's the most basic decision
6:35
making structure but you will see it all
6:41
Okay. So the syntax is just like this.
6:44
If if condition is true
7:06
It's just as simple as that.
7:09
So this is what we are doing it. In the
7:11
next part we'll go one step further.
7:14
We'll cover if else where you have
7:17
multiple choices and it's like a menu
7:20
like if not pizza then maybe pasta or
7:23
else go with any salad. So stick around
7:26
and let's keep building step by step
7:28
together. If you still have any doubts
7:30
regarding the if else structure, syntax,
7:33
why we are doing this, why we are doing
7:35
that. If you have any other doubts, just
7:37
comment down below. We'll try to make
7:39
more simpler version of this video. If
7:42
you learned something from this video,
7:44
then subscribe to this channel and hit
7:46
that like button so that even other
7:49
people who are learning Python can help
7:50
this video to them as well. See you in