1
00:00:00,490 --> 00:00:01,300
Hello, dear friends.

2
00:00:01,780 --> 00:00:05,920
In this lesson, we're going to try to understand conditional statements in Python.

3
00:00:07,240 --> 00:00:08,030
We're going to do it.

4
00:00:08,050 --> 00:00:08,520
Come on.

5
00:00:08,530 --> 00:00:09,280
So let's start.

6
00:00:11,830 --> 00:00:15,340
So first we're going to talk about control statements.

7
00:00:15,820 --> 00:00:21,310
But before that, we need to know about decision making and why we need it.

8
00:00:22,790 --> 00:00:30,950
So decision making is anticipation of conditions occurring while executing the program and specifying

9
00:00:30,950 --> 00:00:33,830
actions taken according to those conditions.

10
00:00:34,780 --> 00:00:41,680
Decision structures evaluate multiple expressions which produce true or false as their outcomes.

11
00:00:42,370 --> 00:00:47,890
So we need to determine which action to take in which statements to execute if the outcome is true or

12
00:00:47,890 --> 00:00:48,880
false otherwise.

13
00:00:49,870 --> 00:00:56,830
So the following is the general form of a typical decision making structure found in most of the programming

14
00:00:56,830 --> 00:00:57,370
languages.

15
00:00:58,240 --> 00:01:04,780
These conditions can be used in several ways, most commonly in if statements and loops.

16
00:01:05,900 --> 00:01:13,130
The Python programming language assumes any non-zero and nominal values to be true, and if it is either

17
00:01:13,130 --> 00:01:16,400
zero or no, then it's assumed to be a false value.

18
00:01:17,760 --> 00:01:18,160
Great.

19
00:01:18,570 --> 00:01:20,850
So now we're ready to learn control statement.

20
00:01:22,190 --> 00:01:25,460
So our first control statement is the if clause.

21
00:01:26,390 --> 00:01:27,920
All right, so what is the statement?

22
00:01:28,820 --> 00:01:34,970
So the if statement contains a logical expression using data to be compared, and then a decision is

23
00:01:34,970 --> 00:01:37,520
made based on the result of the comparison.

24
00:01:38,640 --> 00:01:39,840
But how does that work?

25
00:01:40,590 --> 00:01:49,200
Well, if the Boolean expression evaluates true, then the block of statement or statements inside the

26
00:01:49,200 --> 00:01:50,670
if statement is executed.

27
00:01:51,510 --> 00:01:58,020
And if a boolean expression evaluates to be false, then the first set of code after the end of the

28
00:01:58,020 --> 00:02:00,900
if statement or statements is executed.

29
00:02:02,010 --> 00:02:02,550
I'll tell you what.

30
00:02:02,580 --> 00:02:05,880
Let me show you some examples, and we can both understand it a little bit better.

31
00:02:07,130 --> 00:02:13,910
So create a variable named age and ask for the value to be entered by the user.

32
00:02:19,680 --> 00:02:22,110
So if the age is less than 21.

33
00:02:27,410 --> 00:02:27,800
Prend.

34
00:02:28,220 --> 00:02:29,960
You can't enter this place.

35
00:02:39,980 --> 00:02:47,000
Now, if the user entered value as lesson 21, the program will return us so you can enter this place,

36
00:02:47,510 --> 00:02:51,800
but the user entered value is equal to or greater than 21.

37
00:02:52,160 --> 00:02:53,660
Then the program will return us.

38
00:02:54,760 --> 00:02:55,330
Nothing.

39
00:02:55,600 --> 00:02:56,890
Right, because we didn't mention him.

40
00:02:58,030 --> 00:03:03,790
So let's create another variable named number and we'll ask again for the value to be entered by the

41
00:03:03,790 --> 00:03:04,150
user.

42
00:03:15,310 --> 00:03:17,800
If the number is less than zero.

43
00:03:22,450 --> 00:03:23,500
Print negative.

44
00:03:34,530 --> 00:03:40,290
So now if the user entered values less than zero, that program returns us negative as a result, but.

45
00:03:44,990 --> 00:03:48,560
The user entered value is equal to or greater than zero.

46
00:03:48,770 --> 00:03:50,660
The program will return as nothing.

47
00:03:50,670 --> 00:03:52,430
Yes, because we didn't mention it.

48
00:03:52,760 --> 00:03:53,300
Right.

49
00:03:54,200 --> 00:03:55,130
That's as it should be.

50
00:03:55,880 --> 00:04:01,760
As you can see, we can we well, we're going to just need more information to make the program functional.

51
00:04:02,450 --> 00:04:05,750
That's why we need to know the else statement.

52
00:04:06,950 --> 00:04:07,210
All right.

53
00:04:07,220 --> 00:04:09,410
So what is the P&amp;L statement?

54
00:04:10,510 --> 00:04:17,260
And our statement can be combined with an if statement and statement contains the block of code that

55
00:04:17,260 --> 00:04:24,310
execute if the conditional expression in the if statement resolves to zero or a false value.

56
00:04:25,000 --> 00:04:26,370
But how does our.

57
00:04:27,220 --> 00:04:27,550
Wow.

58
00:04:27,700 --> 00:04:28,810
Let's see some examples.

59
00:04:30,180 --> 00:04:35,640
So first, let's use our examples again and and the else block to the end of it.

60
00:04:36,420 --> 00:04:42,030
If age lesson 21 prent you can't enter this place else print.

61
00:04:42,090 --> 00:04:42,690
Welcome.

62
00:04:55,400 --> 00:04:59,160
Now, if the user entered values lesson 21, the program returns us.

63
00:04:59,180 --> 00:05:05,300
You can enter this place, but if the user entered value is equal to or greater than 21.

64
00:05:06,050 --> 00:05:08,060
The program returns as welcome.

65
00:05:08,730 --> 00:05:11,990
And as you can see, our code is becoming more functional.

66
00:05:11,990 --> 00:05:12,260
Right.

67
00:05:13,490 --> 00:05:15,350
So let's do it to the other example.

68
00:05:16,390 --> 00:05:20,650
If the numbers of us and zero print negative Nel's print positive.

69
00:05:40,360 --> 00:05:47,140
So now if the user enters a value that's less than zero, the program will return as a negative value.

70
00:05:47,140 --> 00:05:53,710
But if the user enters a value that's equal to or greater than zero, then the program returns us a

71
00:05:53,710 --> 00:05:54,760
positive result.

72
00:05:57,660 --> 00:06:02,730
So what if we want to create an el statement without using if.

73
00:06:03,850 --> 00:06:04,110
Ha.

74
00:06:04,510 --> 00:06:05,320
All right, let's try it.

75
00:06:07,210 --> 00:06:08,470
Else print hello.

76
00:06:13,150 --> 00:06:21,130
OK, so as you see, Python returns an error because an else statement is an optional statement, and

77
00:06:21,130 --> 00:06:26,650
there can only be at most only one L statement following if you follow.

78
00:06:28,930 --> 00:06:35,560
So now we can talk about our last conditional statement, the Ayliffe statement, the L.F. statement

79
00:06:35,950 --> 00:06:43,270
allows us to check multiple expressions for true and then execute a block of code as soon as one of

80
00:06:43,270 --> 00:06:45,040
the conditions evaluates to be true.

81
00:06:47,440 --> 00:06:51,400
Similar to the else, the elev statement is optional.

82
00:06:52,270 --> 00:06:59,590
However, unlike Alt for which there can be at most one statement, there can be an arbitrary number

83
00:06:59,590 --> 00:07:01,000
of Ayliffe statements following in.

84
00:07:01,000 --> 00:07:03,640
If so, I'll show you how it works.

85
00:07:05,200 --> 00:07:10,810
So we'll create a variable named model and ask for the value to be entered by the user.

86
00:07:17,860 --> 00:07:22,180
If model equals one print, youchoose Rolls Royce.

87
00:07:32,370 --> 00:07:34,260
Ayliffe model equals to.

88
00:07:37,250 --> 00:07:39,410
Print you choose Aston Martin.

89
00:07:45,020 --> 00:07:46,550
Live model equals three.

90
00:07:50,010 --> 00:07:51,390
You choose Bentley.

91
00:07:56,910 --> 00:07:59,190
Else print invalid number.

92
00:08:06,290 --> 00:08:07,550
And what do we see here?

93
00:08:08,000 --> 00:08:12,140
If the user entered value is one to three.

94
00:08:12,320 --> 00:08:16,580
And the program will return us a value of one to three.

95
00:08:17,360 --> 00:08:21,650
If it is not, and the program will return as an invalid number.

96
00:08:22,370 --> 00:08:26,750
So there's no need to use an LST pattern in the programs.

97
00:08:27,560 --> 00:08:30,260
Our code will work without the else block.

98
00:08:30,980 --> 00:08:37,130
However, if an incorrect action is entered in this case, we will see that nothing is written on the

99
00:08:37,130 --> 00:08:37,550
screen.

100
00:08:38,120 --> 00:08:43,050
So using the else block is entirely optional.

101
00:08:43,070 --> 00:08:43,850
It's up to us.

102
00:08:44,570 --> 00:08:45,950
But you can see how useful it is.

103
00:08:46,580 --> 00:08:51,890
So let's write the previous example again without the URL statement and see what happens.

104
00:08:55,880 --> 00:09:02,060
So as you can see, if the user entered value is in the range between one, two, three, then the program

105
00:09:02,060 --> 00:09:04,670
will return us the value of one to three.

106
00:09:05,300 --> 00:09:08,060
If it is not, then the program will return is nothing.

107
00:09:08,840 --> 00:09:11,450
So using the old block is entirely up to you.

108
00:09:13,410 --> 00:09:19,320
One more thing left Bloche cannot be written unless the if condition is written.

109
00:09:22,160 --> 00:09:25,070
Doing so will cause an error in Python.

110
00:09:25,880 --> 00:09:27,050
Let me show you what that looks like.

111
00:09:30,580 --> 00:09:36,250
All right, so in this lesson, we have learned the basic things we need to know about conditional statements.

112
00:09:36,920 --> 00:09:40,840
Our next lesson, we're going to try to learn the loop concept in Python.

113
00:09:41,260 --> 00:09:43,390
You'll see why reserved it to be separate.

114
00:09:44,710 --> 00:09:45,080
All right.

115
00:09:45,100 --> 00:09:46,150
I'll see you in the next lesson.

116
00:09:46,270 --> 00:09:48,010
Until then, have a nice day.
