1
00:00:00,720 --> 00:00:08,640
If statements allow you to write programs that can make decisions during runtime, depending on data

2
00:00:08,640 --> 00:00:13,860
in the condition that she said so she can see in the Python three documentation here, there is a little

3
00:00:13,860 --> 00:00:20,760
example that shows how to use the if statement and its variations so you can set multiple conditions

4
00:00:20,980 --> 00:00:22,640
during the decision making process.

5
00:00:23,190 --> 00:00:29,050
So let's have a look at this example here, which stems from the example in the documentation.

6
00:00:29,700 --> 00:00:37,680
What I've got in the beginning is an input function that presents a prompt to the user in the show for

7
00:00:37,680 --> 00:00:41,260
the user to type in a number or to provide an entry.

8
00:00:41,880 --> 00:00:49,410
Then, of course, the I.A. casting function so that Python will try to convert whatever the user typed

9
00:00:49,410 --> 00:00:57,690
into a number to down here in lines seven to 14 of got the if statement with a couple of variations.

10
00:00:58,200 --> 00:01:03,930
So the first thing is that the if statement is going to do is to compare whatever the user has typed

11
00:01:03,930 --> 00:01:05,580
them against numerical one.

12
00:01:06,300 --> 00:01:12,810
And if that is true, that type of condition is denoted by the that will equal marks.

13
00:01:12,810 --> 00:01:17,780
A double equals is the equality operator is not the assignment operator.

14
00:01:18,360 --> 00:01:22,950
Then Python is going to print out this message one as a word.

15
00:01:23,930 --> 00:01:31,910
If this comparison turns out to be false, therefore is not one, then Python is going to go into valuate

16
00:01:31,910 --> 00:01:32,990
the second condition.

17
00:01:33,530 --> 00:01:39,770
So the second condition, again, is trying to check to see if the number that I typed is too.

18
00:01:39,920 --> 00:01:45,800
And if it is true, it's going to print out to as they would otherwise, it is going to evaluate the

19
00:01:45,800 --> 00:01:48,290
third and the next condition.

20
00:01:48,590 --> 00:01:51,020
Now, the last one is the fallback.

21
00:01:51,410 --> 00:01:55,780
The last condition is ls will only fire and become true.

22
00:01:55,800 --> 00:01:59,840
So there's no operator here, there's no boolean operator for truthfulness.

23
00:02:00,230 --> 00:02:06,440
It is going to fire if none of the above, none of the previous conditions has fired.

24
00:02:07,340 --> 00:02:14,120
And therefore in this case, if I type anything else other than one of these three options, Python

25
00:02:14,120 --> 00:02:15,560
is going to print out something else.

26
00:02:16,040 --> 00:02:22,490
I've written this into a Python file program instead of running this example in the show like I've done

27
00:02:22,490 --> 00:02:28,940
with previous examples, because quite a few lines of code here, it's just easier to run it repeatedly

28
00:02:28,940 --> 00:02:30,530
by clicking on the green button.

29
00:02:31,610 --> 00:02:39,410
You can click on the green button to run it and I'm going to type, say, two, and the correct answer

30
00:02:39,410 --> 00:02:40,100
comes back.

31
00:02:40,550 --> 00:02:45,260
What happened is that the first condition was attenuated and it came out false.

32
00:02:45,800 --> 00:02:47,660
The second condition was a value added.

33
00:02:47,660 --> 00:02:48,920
It came out true.

34
00:02:49,760 --> 00:02:58,580
Number 10 line was evaluated, printed out the number two in a word, and then the program finished.

35
00:02:59,270 --> 00:03:00,470
Let's do this one more time.

36
00:03:00,680 --> 00:03:06,920
This time I'm going to type in five and five means something else.

37
00:03:07,460 --> 00:03:12,290
So none of the first three conditions were true.

38
00:03:12,680 --> 00:03:19,340
So we went down to the fallback condition, which was line 14.

39
00:03:20,270 --> 00:03:29,210
Of course, for these comparison operators, you can use other as well, not just the equality operator.

40
00:03:30,220 --> 00:03:37,300
Of course, when you make a comparison as part of an if statement, you're not confined to testing for

41
00:03:37,300 --> 00:03:40,180
a quality, you can test for a lot of other things.

42
00:03:40,540 --> 00:03:46,240
You can have a look at the value comparisons section of the Python three, the limitation.

43
00:03:46,480 --> 00:03:54,310
And you can see that operators such as these are also available to less than greater than is equal operator

44
00:03:54,430 --> 00:03:56,560
quality that we've been playing with.

45
00:03:57,370 --> 00:03:59,260
And then you've got a bunch of others as well.

46
00:03:59,530 --> 00:04:05,620
So if you want to know exactly what kind of value comparisons are possible, have a look at this documentation

47
00:04:05,620 --> 00:04:06,040
here.

48
00:04:06,310 --> 00:04:10,330
And it's a lot of information and examples that can help you with this.

49
00:04:10,600 --> 00:04:17,410
And of course, remember that you can also use a string of comparison operators to, for example, you

50
00:04:17,410 --> 00:04:20,710
can say something like this.

51
00:04:22,580 --> 00:04:29,990
So what this is going to do now is going to check whether this is true and this is true, and if both

52
00:04:29,990 --> 00:04:37,930
of these two expressions and comparisons are true, then the whole expression will become true.

53
00:04:38,810 --> 00:04:41,230
So you can make combinations as well.

54
00:04:41,540 --> 00:04:50,270
And has any number of comparisons evaluated as part of a single statement.
