1
00:00:00,510 --> 00:00:02,850
Welcome to the section and conditional statements.

2
00:00:04,380 --> 00:00:10,110
Conditional statements form a very important part of any programming language, and a Python programming

3
00:00:10,110 --> 00:00:13,500
language is no exception to this.

4
00:00:13,920 --> 00:00:15,900
Let's see how conditional statements work.

5
00:00:16,590 --> 00:00:18,090
Say you have a condition.

6
00:00:18,630 --> 00:00:22,770
Now, if this condition is verified, we can take an action.

7
00:00:22,770 --> 00:00:23,490
Say E.

8
00:00:24,240 --> 00:00:27,120
If this condition is not verified, you can take another action.

9
00:00:27,120 --> 00:00:31,110
B Suppose we have several conditions that is.

10
00:00:31,110 --> 00:00:32,490
N Different conditions.

11
00:00:33,000 --> 00:00:40,020
If the first condition, condition one is verified and all the other conditions as Condition I where

12
00:00:40,020 --> 00:00:44,580
I is different from one that is condition to right up to condition and unverified.

13
00:00:44,850 --> 00:00:53,580
Then we can take an action to e one else if this condition two is verified and condition one condition

14
00:00:53,580 --> 00:01:00,180
three of the condition and unverified, we can take an action A2 We're going to repeat this right up

15
00:01:00,180 --> 00:01:06,810
to condition n if condition and is verified on condition one right up to condition and minus one unverified,

16
00:01:06,840 --> 00:01:07,740
you can take an action.

17
00:01:07,750 --> 00:01:13,140
N Now if none of those conditions are verified, we can take an action and plus one.

18
00:01:14,400 --> 00:01:16,350
Let's get a more practical example.

19
00:01:16,950 --> 00:01:24,930
Suppose we want to write a computer program which when you input the fact that your do sports is going

20
00:01:24,930 --> 00:01:26,640
to tell you whether you are healthy or not.

21
00:01:27,420 --> 00:01:29,760
We could simply use condition statements.

22
00:01:30,450 --> 00:01:36,750
We have you that if we have spots that is if you are parts of then.

23
00:01:37,830 --> 00:01:39,690
Wish I'd been out healthy.

24
00:01:40,020 --> 00:01:43,980
And if you're not, then we print out unhealthy now.

25
00:01:44,430 --> 00:01:50,580
We have another example where we have this for sports, football, basketball, volleyball and tennis.

26
00:01:51,030 --> 00:01:58,680
Now we want to bring all the action you make whenever you are playing any of those parts.

27
00:01:59,040 --> 00:02:06,960
So if football is very that is if you are a footballer, then you kick before the goal is made else.

28
00:02:06,990 --> 00:02:09,330
If you're a basketball player, you make it true.

29
00:02:10,380 --> 00:02:13,170
If you're a volleyball, you make a hit.

30
00:02:13,680 --> 00:02:15,960
If you are a tennis player, you make a strike.

31
00:02:16,440 --> 00:02:20,460
And if you are none of this, we could see the action is unknown.

32
00:02:21,180 --> 00:02:22,320
So let's go straight away.

33
00:02:22,320 --> 00:02:25,380
It's look at us index of conditional statements and patent.

34
00:02:26,490 --> 00:02:36,690
So yeah, we have a variable sports so we would say sports true now and the session and valuable times.

35
00:02:36,690 --> 00:02:44,220
What didn't make mention of booleans now actually booleans are some sort of variables which take two

36
00:02:44,220 --> 00:02:46,530
values that is true or false.

37
00:02:46,770 --> 00:02:55,680
So booleans can be this true all false all likes in numbers which take values like so and int which

38
00:02:55,680 --> 00:02:58,260
takes values from negative say infinity.

39
00:02:59,880 --> 00:03:00,240
To.

40
00:03:01,230 --> 00:03:04,880
Positive infinity, which are all whole numbers.

41
00:03:07,290 --> 00:03:13,680
We took in an example with Booleans, we just have this two values, so we either have true or false.

42
00:03:13,950 --> 00:03:19,140
Notice that whenever we print out all, whenever we type out as true, it automatically turns green.

43
00:03:19,140 --> 00:03:21,470
And that's because this is a python keyword.

44
00:03:22,110 --> 00:03:25,680
So let's see how to use this in this example.

45
00:03:25,860 --> 00:03:26,760
So we have sports.

46
00:03:26,760 --> 00:03:27,210
True?

47
00:03:27,660 --> 00:03:31,560
I could say that if sports equals true.

48
00:03:35,400 --> 00:03:37,230
We have Prince.

49
00:03:39,750 --> 00:03:40,380
Healthy.

50
00:03:45,170 --> 00:03:52,510
Now we're receiving this error because we haven't used the right operator now for this F statement.

51
00:03:52,520 --> 00:03:55,460
We have to use the right operator for this to work out well.

52
00:03:56,600 --> 00:04:01,880
Instead of the equals, we actually have the double equals sign.

53
00:04:02,030 --> 00:04:07,070
So if we replace this with this w cosine, we shall see how this works out.

54
00:04:07,610 --> 00:04:09,470
So that works out now perfectly.

55
00:04:10,640 --> 00:04:15,110
It's important to note the syntax of the F statement we actually have.

56
00:04:15,560 --> 00:04:24,890
If we have a condition we have this column and then present enter would take us to the next line.

57
00:04:25,940 --> 00:04:31,100
Now let's look at another way of presenting this is that I've put in spots to be equals.

58
00:04:31,100 --> 00:04:31,400
True.

59
00:04:31,430 --> 00:04:32,720
What would you say if supports?

60
00:04:33,020 --> 00:04:38,990
Now if you say f sports, you are doing the same as seen if sports equals true.

61
00:04:39,800 --> 00:04:44,840
Now, if we change this true to false, we'll see that this is not going to be printed.

62
00:04:45,200 --> 00:04:48,080
So doing this we have not in print it out.

63
00:04:48,920 --> 00:04:51,050
Now, if we have this, we could say else.

64
00:04:51,320 --> 00:05:00,200
So for this, where we had if verified and now if not verify it, that is else we're going to have print,

65
00:05:01,820 --> 00:05:02,780
not healthy.

66
00:05:03,860 --> 00:05:04,820
Not healthy.

67
00:05:05,450 --> 00:05:11,300
And then we go see that we have printed out not healthy because sports is false.

68
00:05:11,300 --> 00:05:15,140
And so when it gets here, this condition is not verified.

69
00:05:15,380 --> 00:05:18,770
And if this condition is not verified, we think else.

70
00:05:19,010 --> 00:05:21,680
What else is actually the opposite of this?

71
00:05:22,100 --> 00:05:26,900
Now, the opposite of this being verified is this being not verified?

72
00:05:27,320 --> 00:05:37,550
So we could replace this else with an Aleph would have live sports equals false and we should have the

73
00:05:37,550 --> 00:05:39,440
same output.

74
00:05:40,370 --> 00:05:42,740
So this is the same as just do it else.

75
00:05:43,940 --> 00:05:44,540
So that's it.

76
00:05:45,110 --> 00:05:46,700
Now let's take this next example.

77
00:05:47,980 --> 00:05:48,610
We have.

78
00:05:51,320 --> 00:05:51,740
See.

79
00:05:53,480 --> 00:05:53,840
Part.

80
00:05:56,480 --> 00:06:03,200
Equals a list made up of the different spots a person actually practices.

81
00:06:03,230 --> 00:06:04,550
So we have this football.

82
00:06:05,030 --> 00:06:07,070
We have basketball.

83
00:06:07,730 --> 00:06:09,230
We have volleyball.

84
00:06:11,940 --> 00:06:13,860
And finally, we have Dennis.

85
00:06:16,060 --> 00:06:16,240
Now.

86
00:06:16,240 --> 00:06:16,840
We should see.

87
00:06:16,870 --> 00:06:19,570
If so, we could put this sparks.

88
00:06:20,860 --> 00:06:21,310
If.

89
00:06:22,850 --> 00:06:23,570
Football.

90
00:06:26,290 --> 00:06:27,640
In sports.

91
00:06:29,590 --> 00:06:30,520
What's the print?

92
00:06:32,370 --> 00:06:36,060
This person plays football.

93
00:06:38,510 --> 00:06:39,140
I leave?

94
00:06:41,160 --> 00:06:44,700
I was always advisable to put this in brackets so we could do this.

95
00:06:46,590 --> 00:06:47,410
And we have here.

96
00:06:47,970 --> 00:06:48,780
So leave.

97
00:06:50,090 --> 00:06:50,960
Basketball.

98
00:06:57,430 --> 00:06:58,270
In sports.

99
00:07:00,700 --> 00:07:01,210
Prince.

100
00:07:04,190 --> 00:07:07,310
This person plays basketball.

101
00:07:12,390 --> 00:07:12,960
A live.

102
00:07:15,550 --> 00:07:19,200
Basketball and sports.

103
00:07:22,490 --> 00:07:23,000
Prince.

104
00:07:29,720 --> 00:07:34,430
This person plays volleyball.

105
00:07:36,350 --> 00:07:37,400
Finally leave.

106
00:07:39,910 --> 00:07:40,540
Dennis.

107
00:07:44,680 --> 00:07:48,070
In sports we have.

108
00:07:51,860 --> 00:07:54,680
This person plays tennis.

109
00:07:55,700 --> 00:08:02,300
Now we have an area that's changed to volleyball and that's it.

110
00:08:02,990 --> 00:08:06,380
So let's run this and we have this person plays football.

111
00:08:06,890 --> 00:08:12,200
Now, this person actually has four different sports he or she practices.

112
00:08:12,710 --> 00:08:17,690
But in this case, or using this method, we actually print out football only.

113
00:08:17,870 --> 00:08:22,070
And that's because once we get into this first condition, we print out what we have first.

114
00:08:22,460 --> 00:08:29,360
And if this condition is verified, we print this and all this other conditions, Aaron's going to be

115
00:08:29,660 --> 00:08:30,420
looked again.

116
00:08:31,160 --> 00:08:34,400
So what the program does, it becomes and test this.

117
00:08:34,400 --> 00:08:41,900
If this is verified, it does this and all of this, other conditions are looked at.

118
00:08:42,350 --> 00:08:48,830
So to solve this problem where we may have situations like this where someone may have four different

119
00:08:48,830 --> 00:08:51,710
sports or could change the way we look at this.

120
00:08:52,310 --> 00:08:56,930
So let's take this cup of this right here.

121
00:08:58,010 --> 00:08:59,510
Now, I see if.

122
00:09:01,290 --> 00:09:01,980
Football.

123
00:09:03,810 --> 00:09:07,950
We're going to spin this so we could have print.

124
00:09:10,470 --> 00:09:11,670
We could actually copy this.

125
00:09:16,540 --> 00:09:17,350
Carpet it is out.

126
00:09:17,560 --> 00:09:25,090
We have brand is now instead of going into the next condition that's shifting to the next line, we

127
00:09:25,090 --> 00:09:29,860
could actually dess next condition in this F statement.

128
00:09:30,070 --> 00:09:32,710
And that is because if this is verified, we could have the next.

129
00:09:33,550 --> 00:09:34,240
Now we have.

130
00:09:34,900 --> 00:09:39,190
If so, here we have if football and sports.

131
00:09:42,160 --> 00:09:43,570
If basketball.

132
00:09:46,660 --> 00:09:47,500
In sports.

133
00:09:49,720 --> 00:09:50,200
Print out.

134
00:09:52,480 --> 00:09:55,740
We could use it that for us to move safely.

135
00:09:55,950 --> 00:09:57,650
What use in space lives when you're.

136
00:09:57,650 --> 00:09:57,970
Yeah.

137
00:09:58,120 --> 00:09:59,200
Avoid doing this.

138
00:10:00,490 --> 00:10:04,030
Instead use simply the tap to get to this point.

139
00:10:04,540 --> 00:10:07,510
And once we have this, we can print this pleasant place basketball.

140
00:10:10,950 --> 00:10:15,830
But on another point may arise where you are in playing football, but you're playing basketball.

141
00:10:15,840 --> 00:10:17,430
So suppose we have something like this.

142
00:10:17,970 --> 00:10:22,440
So in this case, if football in sports is not going to be verified, so we're not going to get into

143
00:10:22,440 --> 00:10:28,320
this now we have to make a way that if we have another condition, you're going to have another condition

144
00:10:28,650 --> 00:10:32,210
where if you're not playing football, we can get into this impasse.

145
00:10:32,220 --> 00:10:35,370
If you're playing basketball now, let's make this problem a bit simpler.

146
00:10:35,880 --> 00:10:36,900
We don't have this.

147
00:10:38,700 --> 00:10:39,480
In fact, we have.

148
00:10:44,100 --> 00:10:45,600
Just football and basketball.

149
00:10:47,700 --> 00:10:49,050
So, yeah, we have the owls.

150
00:10:51,780 --> 00:10:52,260
Prince.

151
00:10:54,280 --> 00:10:56,440
This person, all right?

152
00:10:56,440 --> 00:10:57,880
I don't even print anything, so.

153
00:10:57,880 --> 00:11:06,100
Yeah, we just test if basketball in sports print.

154
00:11:08,230 --> 00:11:11,980
This person plays basketball.

155
00:11:13,810 --> 00:11:14,500
So there we go.

156
00:11:15,310 --> 00:11:16,240
And we run this.

157
00:11:16,390 --> 00:11:19,150
We have this person plays football and pleasant basketball.

158
00:11:19,570 --> 00:11:21,070
So let's take it with basketball.

159
00:11:21,820 --> 00:11:23,500
We have this person plays football.

160
00:11:24,980 --> 00:11:26,620
Let's take a football.

161
00:11:29,520 --> 00:11:31,590
You have this pleasant place, basketball.

162
00:11:33,210 --> 00:11:39,480
But the issue is, if we increase this number of sports, we could have it becomes very difficult to

163
00:11:39,480 --> 00:11:40,950
work with it manually like this.

164
00:11:41,270 --> 00:11:42,630
Well, I would say volleyball.

165
00:11:44,340 --> 00:11:53,340
Volleyball would have to add this if and in this if we have to do an L statement again and then print

166
00:11:53,340 --> 00:11:58,800
out for the volleyball and come here again and print for volleyball and so on and so forth.

167
00:11:58,800 --> 00:12:03,840
So as we increase the number of possibilities for the sports, it becomes very complicated at the court.

168
00:12:04,170 --> 00:12:09,470
And that's where Lupe's come in, and that's what we shall see in the next section with Lopez.

169
00:12:09,480 --> 00:12:12,390
We shall see how to solve this problem very easily.

170
00:12:12,900 --> 00:12:16,050
So let's get back over there with this two for now.

171
00:12:18,880 --> 00:12:21,850
Let's remove this reload.

172
00:12:22,150 --> 00:12:23,110
Everything works fine.

173
00:12:25,390 --> 00:12:27,220
Now let's work with some numbers.

174
00:12:27,460 --> 00:12:29,430
So we have this number equals five.

175
00:12:29,440 --> 00:12:31,270
We have B equals seven.

176
00:12:31,660 --> 00:12:37,360
Good test if E equals five prints.

177
00:12:40,080 --> 00:12:40,590
Stillman.

178
00:12:40,590 --> 00:12:41,160
Correct.

179
00:12:41,700 --> 00:12:42,690
Would you say correct.

180
00:12:45,400 --> 00:12:53,540
We could also have if E is less than B prince, correct?

181
00:12:56,890 --> 00:13:02,590
It could also have if is great and b prince.

182
00:13:07,400 --> 00:13:08,330
Not correct.

183
00:13:10,920 --> 00:13:12,600
If E.

184
00:13:14,590 --> 00:13:19,720
You have a model of B, for example, equals one.

185
00:13:21,730 --> 00:13:22,230
Prince.

186
00:13:24,070 --> 00:13:24,940
Not correct.

187
00:13:28,110 --> 00:13:29,310
And we can load the cell.

188
00:13:29,700 --> 00:13:36,780
Loading the cell, we have this first to correct us because equals five and then here we have 11 B,

189
00:13:36,780 --> 00:13:37,590
which is correct.

190
00:13:37,890 --> 00:13:45,530
Now it good and which is not true because is actually less than b we have a modulo B which in this case

191
00:13:45,530 --> 00:13:48,450
is actually equals five and is not equals one.

192
00:13:48,450 --> 00:13:49,680
So bring out not correct.

193
00:13:49,920 --> 00:13:58,740
And since this is now equals one, we have not printed its out so we could test this prin e one of the

194
00:13:58,750 --> 00:14:01,380
b is clearly five which is now equals one.

195
00:14:01,380 --> 00:14:03,140
So we don't get into this now.

196
00:14:03,240 --> 00:14:03,660
What is that?

197
00:14:03,660 --> 00:14:05,820
Would this are a way of writing?

198
00:14:06,210 --> 00:14:13,200
We get into each and every condition and that is because once we have those, if the program looks for

199
00:14:13,200 --> 00:14:13,680
the next.

200
00:14:14,310 --> 00:14:24,390
So if there is C an L statement here, user prints, whatever, no matter what you have here, is never

201
00:14:24,390 --> 00:14:26,670
going to be printed if this condition is verified.

202
00:14:27,030 --> 00:14:34,020
So like this, for example, this whatever is not printed, but when you have this if statement or when

203
00:14:34,020 --> 00:14:39,690
you have this if statement followed by another, if did mean this other estimate is going to be looked

204
00:14:39,690 --> 00:14:40,020
at.

205
00:14:40,470 --> 00:14:48,060
So what a program does is it looks at if it looks at whether it is elseif ELIF or else and if that is

206
00:14:48,060 --> 00:14:49,770
not there, we just move on.

207
00:14:49,770 --> 00:14:50,700
So we'll go to this.

208
00:14:50,700 --> 00:14:57,060
If two must get into this, if that is different from C in this case where we had Elif would leave.

209
00:14:57,240 --> 00:14:59,520
If this is verify, we don't get into this again.

210
00:14:59,970 --> 00:15:06,600
But what if even if this is verified or if it's verified, this other condition is going to be distant.

211
00:15:07,470 --> 00:15:11,640
Now let's look at the lesson I equals condition.

212
00:15:11,640 --> 00:15:15,630
So here we have the lesson equals operation.

213
00:15:15,900 --> 00:15:16,740
So we have this.

214
00:15:17,700 --> 00:15:19,680
Now let's get what we have here.

215
00:15:19,860 --> 00:15:21,360
So we have this correct.

216
00:15:21,780 --> 00:15:25,890
This lesson equals B this is actually correct because this is less than so.

217
00:15:25,890 --> 00:15:30,660
One of the conditions of a verified and this is not correct, this key is not correct.

218
00:15:31,410 --> 00:15:33,300
So now let's suppose this two are the same.

219
00:15:33,300 --> 00:15:39,780
So let's put this two five we have this other one is printed out and that's simply because let's take

220
00:15:39,780 --> 00:15:46,020
this out and that's simply because with a less than equals, we are saying in this case, if is less

221
00:15:46,020 --> 00:15:46,920
on our equals.

222
00:15:47,220 --> 00:15:47,640
Correct.

223
00:15:48,180 --> 00:15:49,650
And this gives this actually equal.

224
00:15:49,650 --> 00:15:51,900
So we have no problem with that.

225
00:15:52,170 --> 00:15:54,330
In this case, it is greater than all equals.

226
00:15:54,540 --> 00:15:55,570
We can do this.

227
00:15:55,570 --> 00:16:03,960
So this is the same as saying if E is greater than B or E is equals B.

228
00:16:03,960 --> 00:16:07,380
So this is the same statement was common this.

229
00:16:08,890 --> 00:16:09,580
So there we go.

230
00:16:10,060 --> 00:16:11,220
Now, we could take this off

231
00:16:14,380 --> 00:16:15,640
and we're on this.

232
00:16:15,820 --> 00:16:17,440
Still have the same output.

233
00:16:18,070 --> 00:16:23,320
We could also have if equals five, replace with if is five.

234
00:16:23,440 --> 00:16:25,990
So we're going to have this and we'll see that it's actually printed out.

235
00:16:26,440 --> 00:16:27,460
Now, let's take this off.

236
00:16:28,570 --> 00:16:30,130
Yeah, we have if is five.

237
00:16:30,550 --> 00:16:31,120
Correct.

238
00:16:31,600 --> 00:16:33,940
So this is another way of writing.

239
00:16:33,940 --> 00:16:34,930
This equals.

240
00:16:35,470 --> 00:16:36,930
So we just does this direct.

241
00:16:36,970 --> 00:16:38,320
Now, if it's not five.

242
00:16:40,130 --> 00:16:41,210
See they're not in the screen yet.

243
00:16:41,210 --> 00:16:45,620
So we could have else prints not in a sprint printed.

244
00:16:47,430 --> 00:16:48,150
So there we go.

245
00:16:49,320 --> 00:16:51,960
Now that we've seen this, we shall go to the lips.
