1
00:00:00,000 --> 00:00:00,000
Hello guys.

2
00:00:00,000 --> 00:00:03,000
So we are going to continue the discussion with respect to Python.

3
00:00:03,000 --> 00:00:07,000
And in our previous video we have already completed operators.

4
00:00:07,000 --> 00:00:13,000
And if you remember we have completed one complete section with respect to Python basics, uh, we understood

5
00:00:13,000 --> 00:00:14,000
about variables, data types and operators.

6
00:00:14,000 --> 00:00:20,000
Right now we are going to go towards an amazing new topic in Python, which is called as control Flow.

7
00:00:20,000 --> 00:00:24,000
And in Control Flow, we are going to discuss about conditional statement and loops.

8
00:00:24,000 --> 00:00:28,000
In this video we are going to focus more on conditional statement.

9
00:00:28,000 --> 00:00:34,000
So here is the entire video outline what all things we are going to discuss.

10
00:00:34,000 --> 00:00:38,000
So first of all we are going to see introduction to Conditional statements.

11
00:00:38,000 --> 00:00:43,000
Then we'll go and understand what is if statement how to write if statement with the help of Python.

12
00:00:43,000 --> 00:00:47,000
Then you have if statement then you have else if statement.

13
00:00:47,000 --> 00:00:50,000
Then you have nested conditional statements.

14
00:00:50,000 --> 00:00:53,000
Along with this we will be implementing a lot of practical examples.

15
00:00:53,000 --> 00:00:59,000
We I will be showing you multiple examples of real world use case examples, and then we'll try to solve

16
00:00:59,000 --> 00:00:59,000
that.

17
00:00:59,000 --> 00:01:04,000
Apart from that, the final thing is that we'll also see what are the common errors and what is the

18
00:01:04,000 --> 00:01:10,000
best practices that we should follow whenever we are using conditional statement with respect to if

19
00:01:10,000 --> 00:01:11,000
Elif and else.

20
00:01:11,000 --> 00:01:15,000
Now let's go ahead and let's start our coding.

21
00:01:15,000 --> 00:01:19,000
First of all, let's understand what is if statement right.

22
00:01:19,000 --> 00:01:22,000
And this is really important for you all to understand.

23
00:01:22,000 --> 00:01:27,000
And as I have always said before you start any Jupyter notebook, make sure you select the kernel with

24
00:01:27,000 --> 00:01:30,000
respect to the virtual environment that you have created.

25
00:01:30,000 --> 00:01:38,000
Now, if statement evaluates a condition and executes the block of code within it, if the condition

26
00:01:38,000 --> 00:01:40,000
is true, okay, what does this basically mean?

27
00:01:40,000 --> 00:01:44,000
Let's say that I am writing age is equal to 20, right?

28
00:01:44,000 --> 00:01:52,000
And now if I am writing an if statement after this, if we will be putting any conditions over here,

29
00:01:52,000 --> 00:01:55,000
let's say if I write, if age is greater than or equal to 20.

30
00:01:55,000 --> 00:01:57,000
So this is one of the condition.

31
00:01:57,000 --> 00:01:57,000
Right.

32
00:01:57,000 --> 00:02:01,000
So this if statement is going to evaluate this particular condition.

33
00:02:02,000 --> 00:02:07,000
And if it is true right it is going to go inside this particular block.

34
00:02:07,000 --> 00:02:07,000
Right.

35
00:02:07,000 --> 00:02:11,000
And obviously you know about indentation directly.

36
00:02:11,000 --> 00:02:14,000
You will be seeing that we'll be able to write the code inside the block.

37
00:02:14,000 --> 00:02:16,000
So here I will go ahead and write, print.

38
00:02:17,000 --> 00:02:21,000
Um, let's say that uh, I will go ahead and write age 18.

39
00:02:21,000 --> 00:02:25,000
And if the age is greater than or equal to 18, okay.

40
00:02:25,000 --> 00:02:27,000
And here I will go ahead and write 20.

41
00:02:27,000 --> 00:02:27,000
Okay.

42
00:02:28,000 --> 00:02:29,000
Then I will say that.

43
00:02:29,000 --> 00:02:37,000
Hey, uh, you are allowed to vote in the elections, right?

44
00:02:37,000 --> 00:02:38,000
Something like this.

45
00:02:38,000 --> 00:02:39,000
Vote in the elections.

46
00:02:39,000 --> 00:02:42,000
So here you can probably see the output.

47
00:02:42,000 --> 00:02:44,000
You are allowed to vote in the elections.

48
00:02:44,000 --> 00:02:45,000
What does this basically mean?

49
00:02:45,000 --> 00:02:52,000
When I started my if statement, first of all the condition that I have written it, this will get evaluated.

50
00:02:52,000 --> 00:02:58,000
And obviously here you can see the age is greater than or equal to 80 because I have assigned the age

51
00:02:58,000 --> 00:03:01,000
variable is equal to 20 right now.

52
00:03:01,000 --> 00:03:06,000
Since this is greater than or equal to 18, you will be able to see that this entire condition will

53
00:03:06,000 --> 00:03:06,000
become true.

54
00:03:06,000 --> 00:03:08,000
This entire condition will become true.

55
00:03:08,000 --> 00:03:11,000
So it will go ahead and execute this particular statement.

56
00:03:11,000 --> 00:03:12,000
Right.

57
00:03:12,000 --> 00:03:16,000
And this is a very simple way of understanding if statement.

58
00:03:16,000 --> 00:03:21,000
Let me repeat again, A if statement evaluates a condition.

59
00:03:21,000 --> 00:03:27,000
So this is my condition and it executes the block of code within it if the condition is true.

60
00:03:27,000 --> 00:03:29,000
So right now this condition is true.

61
00:03:29,000 --> 00:03:32,000
So that is why it is basically getting executed.

62
00:03:32,000 --> 00:03:34,000
How do I say this condition is true or not.

63
00:03:34,000 --> 00:03:40,000
If I just go and execute in my new cell and if I see age is greater than or equal to 18, this is true.

64
00:03:40,000 --> 00:03:43,000
So if true, I am going to go inside this particular block.

65
00:03:43,000 --> 00:03:45,000
So this was about if statement.

66
00:03:45,000 --> 00:03:48,000
Don't worry we will be seeing a lot of example.

67
00:03:48,000 --> 00:03:54,000
Now let me go ahead and show you the another uh conditional statement which we basically say is else

68
00:03:54,000 --> 00:03:55,000
right now.

69
00:03:55,000 --> 00:03:57,000
What exactly is else okay.

70
00:03:57,000 --> 00:04:02,000
Uh, to define else, I would like to, uh, probably talk about this.

71
00:04:02,000 --> 00:04:02,000
Okay.

72
00:04:02,000 --> 00:04:09,000
And let me just go ahead and write a comment over here again, the else statement executes a block of

73
00:04:09,000 --> 00:04:13,000
code if the condition in the if statement is false.

74
00:04:13,000 --> 00:04:14,000
What does this mean?

75
00:04:14,000 --> 00:04:19,000
That if this statement is false, it is not going to go inside this block, right?

76
00:04:19,000 --> 00:04:23,000
So is there a way that I can probably move it into another block?

77
00:04:23,000 --> 00:04:24,000
Right.

78
00:04:24,000 --> 00:04:27,000
So for that we will be specifically using else statement.

79
00:04:27,000 --> 00:04:30,000
So let us go ahead and see one more example.

80
00:04:31,000 --> 00:04:34,000
So guys now let's go ahead and see this else statement.

81
00:04:34,000 --> 00:04:36,000
And how does it work okay.

82
00:04:36,000 --> 00:04:38,000
Let me just go ahead and write.

83
00:04:39,000 --> 00:04:42,000
Age is equal to 16 okay.

84
00:04:42,000 --> 00:04:45,000
And now you know the condition if you really want to vote.

85
00:04:45,000 --> 00:04:46,000
Right.

86
00:04:46,000 --> 00:04:47,000
So what is the condition that I have to write.

87
00:04:47,000 --> 00:04:51,000
If age is greater than or equal to 18 right.

88
00:04:51,000 --> 00:04:57,000
Then I can go ahead and print something like you are.

89
00:04:57,000 --> 00:05:02,000
You are eligible for voting.

90
00:05:02,000 --> 00:05:04,000
Okay, so this is my statement that I have written, right.

91
00:05:05,000 --> 00:05:07,000
Now let's let's go ahead and execute this.

92
00:05:07,000 --> 00:05:08,000
Right now.

93
00:05:08,000 --> 00:05:11,000
When I'm executing this, you can see that nothing is getting printed.

94
00:05:11,000 --> 00:05:16,000
The reason is very simple because this statement has become false.

95
00:05:16,000 --> 00:05:16,000
Right.

96
00:05:16,000 --> 00:05:19,000
And so you are actually coming outside the block.

97
00:05:19,000 --> 00:05:20,000
Nothing is getting printed.

98
00:05:20,000 --> 00:05:26,000
But let's say I want to handle for this age in a separate way within this if clause.

99
00:05:26,000 --> 00:05:26,000
Right.

100
00:05:26,000 --> 00:05:33,000
So what I can do, I can again go ahead and write else clause right now inside this else clause I will

101
00:05:33,000 --> 00:05:40,000
probably say print you are a minor okay.

102
00:05:40,000 --> 00:05:42,000
So this will be my else block.

103
00:05:42,000 --> 00:05:44,000
Now what will happen if I execute this?

104
00:05:44,000 --> 00:05:49,000
You'll be seeing that if this is false, what it is going to do by default, it is going to jump into

105
00:05:49,000 --> 00:05:50,000
this particular block.

106
00:05:50,000 --> 00:05:50,000
Right.

107
00:05:50,000 --> 00:05:53,000
Because this is what my else condition is, right?

108
00:05:53,000 --> 00:05:54,000
The default condition at the end.

109
00:05:54,000 --> 00:05:55,000
Right?

110
00:05:55,000 --> 00:06:00,000
If nothing is getting satisfied, just go and jump to the last else block and display this.

111
00:06:00,000 --> 00:06:05,000
So once I'm executing this, you'll be able to see that here you are getting an answer.

112
00:06:05,000 --> 00:06:05,000
You are a minor.

113
00:06:05,000 --> 00:06:09,000
So this became false after this basically became false.

114
00:06:09,000 --> 00:06:10,000
It is going to the else block.

115
00:06:10,000 --> 00:06:10,000
Again.

116
00:06:10,000 --> 00:06:16,000
Let me repeat the else statement executes a block of code if the condition in the if statement is false

117
00:06:16,000 --> 00:06:19,000
okay so here you get probably see this okay.

118
00:06:19,000 --> 00:06:26,000
Now let me just go ahead and go ahead with the next conditional statement which is called as Elif statement.

119
00:06:26,000 --> 00:06:26,000
Okay.

120
00:06:26,000 --> 00:06:33,000
Now with respect to the Elif statement, um, if I really want to give a smaller definition for this.

121
00:06:33,000 --> 00:06:33,000
What?

122
00:06:33,000 --> 00:06:35,000
Okay, what exactly is an if statement?

123
00:06:36,000 --> 00:06:40,000
Now, this Elif statement allows you to check multiple condition.

124
00:06:40,000 --> 00:06:43,000
It stands for else if.

125
00:06:43,000 --> 00:06:45,000
Okay, that is the reason we say Elif.

126
00:06:45,000 --> 00:06:46,000
Elif statement is there.

127
00:06:46,000 --> 00:06:50,000
But if we go ahead and see the full form, it is nothing but Elif, okay?

128
00:06:50,000 --> 00:06:52,000
And it allows you to check for multiple condition.

129
00:06:52,000 --> 00:06:58,000
Okay, now let me just go ahead and probably put some, uh, points over here.

130
00:06:58,000 --> 00:07:00,000
Let's say I'll show you some example.

131
00:07:00,000 --> 00:07:03,000
If I go ahead and write age is equal to 20.

132
00:07:03,000 --> 00:07:03,000
Okay.

133
00:07:03,000 --> 00:07:04,000
Now let me go ahead and write.

134
00:07:04,000 --> 00:07:08,000
If age is less than 13.

135
00:07:08,000 --> 00:07:09,000
Okay.

136
00:07:09,000 --> 00:07:11,000
I'm putting some kind of condition over here.

137
00:07:11,000 --> 00:07:16,000
Any condition you can put, you can go ahead and put an end condition or condition, whatever condition

138
00:07:16,000 --> 00:07:18,000
you want, any conditional statements, you can write it over here.

139
00:07:19,000 --> 00:07:24,000
Um, you know, and obviously I've seen this kind of, uh, statements right where I am actually putting

140
00:07:24,000 --> 00:07:26,000
some kind of conditions over here.

141
00:07:26,000 --> 00:07:26,000
Right?

142
00:07:26,000 --> 00:07:28,000
Uh, anything you can actually put over there.

143
00:07:28,000 --> 00:07:35,000
Now, if I go ahead and write print, if age is less than 13, I will say, hey, you are a child,

144
00:07:35,000 --> 00:07:35,000
okay?

145
00:07:35,000 --> 00:07:36,000
You are a child.

146
00:07:36,000 --> 00:07:38,000
Now I want to check for other condition.

147
00:07:38,000 --> 00:07:41,000
Also lets me go ahead and write Elif.

148
00:07:41,000 --> 00:07:43,000
Now Elif, age is less than 18.

149
00:07:44,000 --> 00:07:47,000
Okay, if the if the age is less than 18, then I will go ahead and say, print.

150
00:07:48,000 --> 00:07:50,000
You are a teenager.

151
00:07:50,000 --> 00:07:53,000
Okay, you are a teenager, right?

152
00:07:53,000 --> 00:07:55,000
And then I will go ahead and write.

153
00:07:55,000 --> 00:07:56,000
Else.

154
00:07:56,000 --> 00:07:58,000
Finally, the else statement.

155
00:07:58,000 --> 00:08:00,000
By default this will get.

156
00:08:00,000 --> 00:08:04,000
If none of this condition is basically becoming true, this will get executed.

157
00:08:04,000 --> 00:08:11,000
Then if I go ahead and write over here print, I'll say, hey, you are an adult, okay?

158
00:08:11,000 --> 00:08:13,000
And now if I go ahead and execute it, what will happen?

159
00:08:13,000 --> 00:08:18,000
Which part will get basically executed, whether this or this or this.

160
00:08:18,000 --> 00:08:18,000
Right.

161
00:08:18,000 --> 00:08:23,000
So here you can probably see if I go ahead and execute, you'll be able to see, hey, you are an adult

162
00:08:23,000 --> 00:08:24,000
right now.

163
00:08:24,000 --> 00:08:28,000
If I go ahead and write 17 as my age.

164
00:08:28,000 --> 00:08:29,000
Right.

165
00:08:29,000 --> 00:08:33,000
So first condition over here you can see age is less than 13, which is obviously false.

166
00:08:33,000 --> 00:08:34,000
It will go to the next one.

167
00:08:34,000 --> 00:08:39,000
Else if it is not going to check multiple condition if else if age is equal to 18.

168
00:08:39,000 --> 00:08:43,000
Now here it is going to be true and this is what it is going to get displayed right.

169
00:08:43,000 --> 00:08:46,000
So here you can see you are a teenager right.

170
00:08:47,000 --> 00:08:52,000
So this actually gives you an idea how this Elif basically works.

171
00:08:52,000 --> 00:08:52,000
Right.

172
00:08:52,000 --> 00:08:56,000
And Elif allows you to check multiple conditions right now.

173
00:08:56,000 --> 00:09:02,000
Uh, there may be scenario where I really want to use nested conditional statement.

174
00:09:02,000 --> 00:09:05,000
And this is what we are going to discuss about okay.

175
00:09:05,000 --> 00:09:09,000
Nested conditional statements.

176
00:09:10,000 --> 00:09:14,000
Conditional statements right now nested conditional statement.

177
00:09:14,000 --> 00:09:17,000
What all things you can basically do okay.

178
00:09:18,000 --> 00:09:23,000
We can use the combination of if else if or else inside the block like.

179
00:09:24,000 --> 00:09:27,000
Let's say inside this if clause I can write another if clause.

180
00:09:27,000 --> 00:09:27,000
Right.

181
00:09:27,000 --> 00:09:31,000
So here let me just go ahead and write this particular comment for you.

182
00:09:31,000 --> 00:09:40,000
You can place one or more if Elif or else statement inside another if Elif or else statement to create

183
00:09:40,000 --> 00:09:42,000
nested conditional statement.

184
00:09:42,000 --> 00:09:48,000
Okay, now let's say, uh, I will just give you some of the examples over here to make you understand,

185
00:09:49,000 --> 00:09:55,000
uh, what uh, like let's say I want to probably I will give you a number number.

186
00:09:55,000 --> 00:10:02,000
You need to tell me whether it is even or odd or negative.

187
00:10:02,000 --> 00:10:02,000
Okay.

188
00:10:02,000 --> 00:10:04,000
Something like this.

189
00:10:04,000 --> 00:10:05,000
These are my three conditions.

190
00:10:05,000 --> 00:10:06,000
Okay.

191
00:10:06,000 --> 00:10:07,000
Let's say I have given my number.

192
00:10:07,000 --> 00:10:10,000
So let me go ahead and write input.

193
00:10:10,000 --> 00:10:11,000
Okay.

194
00:10:11,000 --> 00:10:14,000
So first of all I will define my number I will use int.

195
00:10:14,000 --> 00:10:16,000
And then here I'm going to use input.

196
00:10:16,000 --> 00:10:21,000
And here I'm going to probably say enter the number okay I will go ahead and enter the number.

197
00:10:21,000 --> 00:10:26,000
Now my first condition will be that I will go ahead and check for positive and negative number.

198
00:10:26,000 --> 00:10:30,000
So if I go ahead and write if number is greater than or equal to zero, sorry.

199
00:10:30,000 --> 00:10:33,000
If it is greater than zero, then I can probably.

200
00:10:33,000 --> 00:10:35,000
Okay, let me just go ahead and write.

201
00:10:35,000 --> 00:10:37,000
Then I can probably go ahead and print.

202
00:10:38,000 --> 00:10:44,000
The number is the number is positive right.

203
00:10:44,000 --> 00:10:47,000
So here you'll be able to see that I am printing this okay.

204
00:10:47,000 --> 00:10:52,000
Now the next condition is that I need to check whether this number is even or odd right now.

205
00:10:52,000 --> 00:10:56,000
In order to probably check I may write any numerical conditions over here.

206
00:10:56,000 --> 00:11:00,000
If number, I mean, I will try to use any operators, right.

207
00:11:00,000 --> 00:11:01,000
If number.

208
00:11:01,000 --> 00:11:02,000
Modulus of two.

209
00:11:02,000 --> 00:11:03,000
Modulus of.

210
00:11:03,000 --> 00:11:06,000
Two basically means if the remainder is equal to zero, that basically indicates that.

211
00:11:06,000 --> 00:11:08,000
Obviously this is an even number.

212
00:11:08,000 --> 00:11:15,000
So here I'm going to print the number is even right.

213
00:11:15,000 --> 00:11:21,000
So here you can see the number is even else I'm going to probably print.

214
00:11:23,000 --> 00:11:25,000
The number is odd.

215
00:11:26,000 --> 00:11:29,000
Okay, so here you can see what I have actually done.

216
00:11:29,000 --> 00:11:35,000
If this if this gets solved, that basically means we are going to say that hey, the number is even.

217
00:11:35,000 --> 00:11:40,000
But if this is not true, then it will go to the else block saying that the number is odd.

218
00:11:40,000 --> 00:11:44,000
So what is basically happening inside an if condition?

219
00:11:44,000 --> 00:11:46,000
I have written another if condition along with else block.

220
00:11:46,000 --> 00:11:53,000
So this is what nested nested uh, nested uh conditional statement means right now there is also one

221
00:11:53,000 --> 00:11:57,000
more thing for this if block, also for the outer if block.

222
00:11:57,000 --> 00:12:00,000
Also I can again write an else condition saying that else.

223
00:12:00,000 --> 00:12:08,000
And this time I will go ahead and print the number is the number is negative okay.

224
00:12:08,000 --> 00:12:14,000
Or a better way will be that if I'm entering the number, I will just go ahead and write greater than

225
00:12:14,000 --> 00:12:14,000
zero.

226
00:12:14,000 --> 00:12:15,000
Okay.

227
00:12:15,000 --> 00:12:20,000
And here in the else condition I will go ahead and write is zero or negative.

228
00:12:20,000 --> 00:12:20,000
Okay.

229
00:12:20,000 --> 00:12:24,000
Now see this is what nested conditional statement means.

230
00:12:24,000 --> 00:12:32,000
You can place one or if else or uh if else or else if uh sorry Elif this kind of statements within another

231
00:12:32,000 --> 00:12:34,000
if clause or uh, Lf clause.

232
00:12:34,000 --> 00:12:35,000
Okay.

233
00:12:35,000 --> 00:12:39,000
Similarly you can write another Lf clause over here wherever you specifically want.

234
00:12:39,000 --> 00:12:41,000
But the order will be the same thing right?

235
00:12:41,000 --> 00:12:45,000
You need to probably make sure that you manage all the indentation part.

236
00:12:45,000 --> 00:12:49,000
If you are not managing the indentation part then you may get an error.

237
00:12:49,000 --> 00:12:52,000
Okay, so here you go over here.

238
00:12:52,000 --> 00:12:58,000
And now if I go ahead and execute this you will be able to see it is asking for me for a number.

239
00:12:58,000 --> 00:13:01,000
If I go ahead and write 12, I'll go ahead and press enter.

240
00:13:01,000 --> 00:13:05,000
So here you can see the number is positive and number is also even.

241
00:13:05,000 --> 00:13:05,000
Okay.

242
00:13:05,000 --> 00:13:07,000
Again let me just go ahead and execute this time.

243
00:13:07,000 --> 00:13:11,000
If I give 11 you will be able to see number is positive but the number is odd.

244
00:13:11,000 --> 00:13:14,000
The else part has got executed over here.

245
00:13:14,000 --> 00:13:18,000
Now again if I go ahead and execute it and if I go ahead and write minus one.

246
00:13:18,000 --> 00:13:23,000
So here you can see the number is zero or negative which is basically going to the else block.

247
00:13:23,000 --> 00:13:23,000
Right.

248
00:13:23,000 --> 00:13:25,000
Why this is going to the else block.

249
00:13:25,000 --> 00:13:27,000
Because I have given the number as minus one.

250
00:13:27,000 --> 00:13:31,000
Now this is going to be false and it is just going to jump to the else block.

251
00:13:31,000 --> 00:13:31,000
Right.

252
00:13:31,000 --> 00:13:36,000
So I hope, uh, you are able to understand this in a amazing way.

253
00:13:36,000 --> 00:13:40,000
Uh, you got an idea with respect to if else if else.

254
00:13:40,000 --> 00:13:44,000
And also you got an idea with respect to the nested conditional statement.

255
00:13:44,000 --> 00:13:48,000
Now let us see some very important use cases.

256
00:13:48,000 --> 00:13:54,000
And uh, I'll just say that, uh, some practical examples that we are going to probably discuss.

257
00:13:54,000 --> 00:13:55,000
Okay.

258
00:13:55,000 --> 00:14:00,000
See, the errors can only happen when you are not doing the proper indentation over here.

259
00:14:00,000 --> 00:14:00,000
Right?

260
00:14:00,000 --> 00:14:05,000
If the indentation is basically done in a proper way, then you should be able to write this if else

261
00:14:05,000 --> 00:14:07,000
block in a very efficient way.

262
00:14:07,000 --> 00:14:07,000
Okay.

263
00:14:07,000 --> 00:14:11,000
Now first practical example that I'm actually going to give you Okay.

264
00:14:12,000 --> 00:14:19,000
You need to determine if a year is a leap year.

265
00:14:19,000 --> 00:14:21,000
What does leap year basically mean.

266
00:14:21,000 --> 00:14:23,000
Any year that is divided by four.

267
00:14:23,000 --> 00:14:32,000
If the remainder is zero, that that basically means it is a leap year using nested conditional statement.

268
00:14:32,000 --> 00:14:36,000
Now you can pause the video and you can start writing this right.

269
00:14:36,000 --> 00:14:41,000
And you can see what it will probably give you and what it will not give you.

270
00:14:41,000 --> 00:14:42,000
Okay.

271
00:14:42,000 --> 00:14:44,000
Now let me just go ahead and write this.

272
00:14:44,000 --> 00:14:47,000
So first of all, I will go ahead and write here.

273
00:14:47,000 --> 00:14:49,000
And I will give this as an input okay.

274
00:14:49,000 --> 00:14:53,000
And let me just go ahead and say enter the year okay.

275
00:14:53,000 --> 00:14:55,000
Enter the year okay.

276
00:14:55,000 --> 00:15:07,000
Now next thing if I will start my condition, if your modulus for right is double equal to zero right.

277
00:15:07,000 --> 00:15:10,000
So here see understand this particular condition.

278
00:15:10,000 --> 00:15:14,000
Also if your modular for is equal to zero right then what I will do see here.

279
00:15:14,000 --> 00:15:16,000
Also I can also write like this.

280
00:15:17,000 --> 00:15:23,000
If number percentile uh modulus two is equal to double equal to zero I have used one additional bracket.

281
00:15:23,000 --> 00:15:24,000
So let me just remove this.

282
00:15:24,000 --> 00:15:26,000
If you are getting confused with this okay.

283
00:15:26,000 --> 00:15:32,000
If it is double equal to zero then I will also go ahead and put one more condition.

284
00:15:32,000 --> 00:15:36,000
If here modulo 100 is double equal to zero right.

285
00:15:36,000 --> 00:15:39,000
So here I have used two nested if else clause.

286
00:15:39,000 --> 00:15:39,000
Right.

287
00:15:39,000 --> 00:15:41,000
And if here.

288
00:15:43,000 --> 00:15:47,000
Or modulus 400 double equal to zero okay.

289
00:15:47,000 --> 00:15:50,000
Okay, so see how many nested if else we have actually done.

290
00:15:50,000 --> 00:15:51,000
Okay.

291
00:15:51,000 --> 00:15:57,000
Now if this condition is basically if this all three condition is basically true, which is specifically

292
00:15:57,000 --> 00:16:02,000
for the leap year, what I'm actually going to do, I'm going to go ahead and write print this year,

293
00:16:02,000 --> 00:16:03,000
whatever I've actually given.

294
00:16:04,000 --> 00:16:04,000
Right.

295
00:16:04,000 --> 00:16:09,000
Whatever year I've actually given is a leap year.

296
00:16:09,000 --> 00:16:11,000
Okay is a leap year.

297
00:16:11,000 --> 00:16:14,000
So here is how I'm actually using the print statement.

298
00:16:14,000 --> 00:16:18,000
Okay, I will take one more session with respect to the print formatting.

299
00:16:18,000 --> 00:16:18,000
Okay.

300
00:16:18,000 --> 00:16:20,000
Uh, there are different different ways of print formatting.

301
00:16:20,000 --> 00:16:22,000
So print year is a leap year.

302
00:16:22,000 --> 00:16:22,000
Okay.

303
00:16:22,000 --> 00:16:25,000
Then I will go ahead and write in the else block.

304
00:16:25,000 --> 00:16:26,000
What if this is not true?

305
00:16:26,000 --> 00:16:29,000
What if this two statements are true?

306
00:16:29,000 --> 00:16:30,000
But this is not true right?

307
00:16:30,000 --> 00:16:32,000
Then I will go ahead and print this.

308
00:16:32,000 --> 00:16:35,000
Here is not a leap year, right?

309
00:16:35,000 --> 00:16:40,000
The same year is not a leap year okay.

310
00:16:40,000 --> 00:16:43,000
So here you can probably see this okay.

311
00:16:43,000 --> 00:16:46,000
Then let's say fine for this.

312
00:16:46,000 --> 00:16:49,000
If if it is false I'm handling it over here.

313
00:16:49,000 --> 00:16:50,000
But what about this.

314
00:16:50,000 --> 00:16:53,000
If so for this we will write another else statement okay.

315
00:16:53,000 --> 00:17:01,000
And here I will also give one more condition saying that hey print here.

316
00:17:02,000 --> 00:17:10,000
And if this is also true, if your 100 model is 100 is equal to zero, I will be saying that hey, here

317
00:17:10,000 --> 00:17:11,000
is a leap year.

318
00:17:12,000 --> 00:17:14,000
Okay is a leap year.

319
00:17:15,000 --> 00:17:19,000
I'm just trying to write it in a complex, uh, if else condition.

320
00:17:19,000 --> 00:17:25,000
And finally, if this condition is also true in the else block, I will go ahead and basically go ahead

321
00:17:25,000 --> 00:17:29,000
and write print, print.

322
00:17:31,000 --> 00:17:32,000
Here.

323
00:17:35,000 --> 00:17:37,000
Is not a leap year.

324
00:17:37,000 --> 00:17:38,000
Okay.

325
00:17:38,000 --> 00:17:38,000
Done.

326
00:17:39,000 --> 00:17:44,000
So here you can basically see that if this condition is true then also we know that it is a leap year.

327
00:17:44,000 --> 00:17:47,000
So for that further conditions we are applying this one.

328
00:17:47,000 --> 00:17:49,000
Then again further we are applying this one.

329
00:17:49,000 --> 00:17:52,000
But if this is also not true then we also need to handle in the else block.

330
00:17:52,000 --> 00:17:55,000
Right now let me just go ahead and try it out.

331
00:17:55,000 --> 00:17:56,000
So here I'm just going to execute it.

332
00:17:56,000 --> 00:17:59,000
And let's say I go ahead and write 2022.

333
00:17:59,000 --> 00:18:04,000
Now obviously this will be uh not a leap year, but let's execute this.

334
00:18:04,000 --> 00:18:07,000
And here you can see 2022 is not a leap year, right.

335
00:18:07,000 --> 00:18:09,000
If I go ahead and execute it again.

336
00:18:09,000 --> 00:18:11,000
So let's go ahead and see 2024.

337
00:18:11,000 --> 00:18:15,000
If I go ahead and execute over here, 2024 is a leap year right now.

338
00:18:15,000 --> 00:18:18,000
So this is one of the good, amazing, practical example.

339
00:18:18,000 --> 00:18:22,000
Now what I'm going to do is that I'm going to give you more assignments as we go ahead.

340
00:18:23,000 --> 00:18:23,000
Right.

341
00:18:24,000 --> 00:18:28,000
Uh, we need to also understand what are the common errors and mistakes that we usually do.

342
00:18:28,000 --> 00:18:33,000
If you have not written colon, if the indentation part is not done proper properly, then obviously

343
00:18:33,000 --> 00:18:36,000
this will be a problem right now.

344
00:18:36,000 --> 00:18:41,000
Uh, let me give you some of the assignments, uh, which you should definitely do.

345
00:18:41,000 --> 00:18:42,000
Okay.

346
00:18:42,000 --> 00:18:46,000
One is, uh, please try to create a simple calculator.

347
00:18:46,000 --> 00:18:50,000
A simple calculator calculator.

348
00:18:50,000 --> 00:18:56,000
And inside a simple calculator program, you need to take an input from the user, perform different,

349
00:18:56,000 --> 00:18:59,000
different operations, what kind of operations you need to do.

350
00:18:59,000 --> 00:19:04,000
If it is plus, then by using if else condition, you really need to do it.

351
00:19:04,000 --> 00:19:06,000
So here I will just be.

352
00:19:06,000 --> 00:19:12,000
Please make sure that first of all, before I show you the solution, you try to write the code from

353
00:19:12,000 --> 00:19:12,000
your side.

354
00:19:12,000 --> 00:19:21,000
Okay, so here you can see, uh, I will just go ahead and update this just a second.

355
00:19:24,000 --> 00:19:25,000
Okay.

356
00:19:26,000 --> 00:19:29,000
so here you can probably see I have used float input.

357
00:19:29,000 --> 00:19:30,000
Enter the first number.

358
00:19:30,000 --> 00:19:35,000
Second number operation is either you can upload plus minus star or division.

359
00:19:35,000 --> 00:19:37,000
You can also use modulus if you want.

360
00:19:37,000 --> 00:19:39,000
And then I have written all this condition.

361
00:19:39,000 --> 00:19:40,000
It's operation is equal to plus.

362
00:19:40,000 --> 00:19:46,000
Then result num plus one this this this else you'll be also able to see the nested elsif is also there.

363
00:19:46,000 --> 00:19:48,000
Else if if number is not equal to zero right.

364
00:19:48,000 --> 00:19:50,000
Just go ahead and see this.

365
00:19:50,000 --> 00:19:53,000
Whatever things we have discussed till now, I think you should be able to understand it.

366
00:19:53,000 --> 00:19:54,000
Okay.

367
00:19:54,000 --> 00:19:55,000
So let me just go ahead and execute it.

368
00:19:55,000 --> 00:19:57,000
Let's say 12.

369
00:19:57,000 --> 00:20:00,000
I'll go ahead and press 24.

370
00:20:00,000 --> 00:20:01,000
I'll go ahead and press enter.

371
00:20:01,000 --> 00:20:03,000
And let's say I want to do plus operation.

372
00:20:03,000 --> 00:20:06,000
So here you can see 36.0 okay.

373
00:20:06,000 --> 00:20:08,000
So uh try to do this.

374
00:20:08,000 --> 00:20:12,000
Uh one more example that I really want to give it to you okay.

375
00:20:12,000 --> 00:20:16,000
Determine the ticket price based on the age.

376
00:20:17,000 --> 00:20:17,000
Okay.

377
00:20:17,000 --> 00:20:19,000
So this will be another one example.

378
00:20:19,000 --> 00:20:21,000
So I have multiple examples.

379
00:20:21,000 --> 00:20:23,000
But definitely do try it from your side.

380
00:20:23,000 --> 00:20:28,000
So I'm just putting so that you will be able to practice it okay.

381
00:20:28,000 --> 00:20:30,000
So here you can see enter your age.

382
00:20:30,000 --> 00:20:32,000
Are you a student yes or no.

383
00:20:32,000 --> 00:20:37,000
So if you are probably saying yes then you will be seeing yes over here.

384
00:20:37,000 --> 00:20:39,000
So here are some of the condition.

385
00:20:39,000 --> 00:20:44,000
If age is less than five, price is free, else if is age is less than 12, price is $10.

386
00:20:44,000 --> 00:20:50,000
If age is less than 17, and if the student if it is a student, then price is $12.

387
00:20:50,000 --> 00:20:54,000
Else if $15 then just try to go through this okay.

388
00:20:54,000 --> 00:20:56,000
And then you will be able to understand it.

389
00:20:56,000 --> 00:20:59,000
So I hope you were able to understand this video.

390
00:20:59,000 --> 00:21:01,000
Uh, this was it from my side.

391
00:21:01,000 --> 00:21:02,000
I will see you all in the next video.

392
00:21:02,000 --> 00:21:03,000
Thank you.

