WEBVTT

00:00.120 --> 00:01.040
Welcome back.

00:01.080 --> 00:06.360
Sometimes you want your program to do different things based on certain conditions.

00:06.640 --> 00:12.040
Python uses if Elif which is else, if and else for decision making.

00:12.200 --> 00:16.880
For example, we have this age equals to 15 age variable.

00:16.920 --> 00:22.200
Let me test this age variable and make conditions according to this value.

00:22.360 --> 00:26.680
If age greater than or equal to 18, go and print.

00:26.680 --> 00:28.600
You are old enough to vote.

00:28.640 --> 00:33.320
Otherwise, if age is less than 18, go and print.

00:33.320 --> 00:35.800
Sorry, you are too young to vote.

00:35.840 --> 00:39.440
Run the application age equals to 15.

00:39.560 --> 00:43.080
Sorry your your are too young to vote.

00:43.120 --> 00:44.760
Change it to 20.

00:45.040 --> 00:48.480
Run the cell you are old enough to vote.

00:48.480 --> 00:52.240
So here we are using the age to check its value.

00:52.240 --> 00:58.760
If it is greater than 18, go and print this and if it is less than 18, go and print.

00:58.760 --> 01:01.120
Sorry, you're too young to vote.

01:01.160 --> 01:04.480
You can check multiple conditions using Elif.

01:04.600 --> 01:09.200
For example, if our age equals to 20, here we have three.

01:09.720 --> 01:12.590
Uh, three options.

01:12.590 --> 01:16.390
If age is less than 13, print you are a child.

01:16.390 --> 01:18.550
If it is less than 18.

01:18.750 --> 01:21.070
Create a new message.

01:21.270 --> 01:26.110
You're a teenager, and if it is greater than 18, print.

01:26.110 --> 01:27.710
You are an adult.

01:27.710 --> 01:29.870
Let me run and here we go.

01:29.910 --> 01:31.270
You are an adult.

01:31.310 --> 01:33.190
Change it to 15.

01:33.190 --> 01:36.910
For example, run the cell and you are a teenager.

01:36.910 --> 01:38.990
We are printing this state.

01:39.030 --> 01:41.230
Change it to ten here.

01:41.270 --> 01:42.990
If age is less than ten.

01:43.030 --> 01:46.030
Yes, the program puts ten here.

01:46.150 --> 01:48.070
The value of age which is ten.

01:48.110 --> 01:49.670
Ten less than 13.

01:49.710 --> 01:50.190
Yes.

01:50.190 --> 01:50.510
True.

01:50.550 --> 01:54.270
Go and execute this line of code which is printing.

01:54.270 --> 01:55.830
You are a child.

01:56.030 --> 02:00.950
So in this way the Python compiler executes the code.

02:00.990 --> 02:05.830
Okay, you can even nest if statements inside others.

02:05.830 --> 02:13.910
For example, we have age equals to 15 and we have another variable called has permission which is set

02:13.910 --> 02:14.710
it to true.

02:14.710 --> 02:20.430
Now if age equals to 18 or age less than 18.

02:20.470 --> 02:21.150
Print.

02:21.150 --> 02:27.790
You are a teenager now inside this if we need to create a nested if condition.

02:27.830 --> 02:30.710
Another nested if condition here.

02:30.830 --> 02:36.590
If we have a permission, go and you can watch PG 13 movies.

02:36.750 --> 02:40.270
Else print you need parental permissions.

02:40.270 --> 02:42.310
Let me test and see.

02:42.550 --> 02:45.030
You are a teenager.

02:45.070 --> 02:48.590
You can watch PG 13 movies.

02:48.790 --> 02:52.950
Now let me make this to false run.

02:52.990 --> 02:54.390
You are a teenager.

02:54.430 --> 02:58.030
True, you need parental permissions.

02:58.070 --> 03:07.470
Okay, so here we learned how to create a nested conditional statement inside the outer conditional

03:07.510 --> 03:08.270
statement.

03:08.310 --> 03:16.710
Okay you see guys how we use this conditional statements and the nested conditional statements.

03:16.710 --> 03:25.350
And those are very crucial for our decision making and for our programs because we need to create a

03:25.350 --> 03:29.510
lot of those conditional statements in our programs.
