If statements allow you to write programs that can make decisions during runtime, depending on data
in the condition that she said so she can see in the Python three documentation here, there is a little
example that shows how to use the if statement and its variations so you can set multiple conditions
during the decision making process.
So let's have a look at this example here, which stems from the example in the documentation.
What I've got in the beginning is an input function that presents a prompt to the user in the show for
the user to type in a number or to provide an entry.
Then, of course, the I.A. casting function so that Python will try to convert whatever the user typed
into a number to down here in lines seven to 14 of got the if statement with a couple of variations.
So the first thing is that the if statement is going to do is to compare whatever the user has typed
them against numerical one.
And if that is true, that type of condition is denoted by the that will equal marks.
A double equals is the equality operator is not the assignment operator.
Then Python is going to print out this message one as a word.
If this comparison turns out to be false, therefore is not one, then Python is going to go into valuate
the second condition.
So the second condition, again, is trying to check to see if the number that I typed is too.
And if it is true, it's going to print out to as they would otherwise, it is going to evaluate the
third and the next condition.
Now, the last one is the fallback.
The last condition is ls will only fire and become true.
So there's no operator here, there's no boolean operator for truthfulness.
It is going to fire if none of the above, none of the previous conditions has fired.
And therefore in this case, if I type anything else other than one of these three options, Python
is going to print out something else.
I've written this into a Python file program instead of running this example in the show like I've done
with previous examples, because quite a few lines of code here, it's just easier to run it repeatedly
by clicking on the green button.
You can click on the green button to run it and I'm going to type, say, two, and the correct answer
comes back.
What happened is that the first condition was attenuated and it came out false.
The second condition was a value added.
It came out true.
Number 10 line was evaluated, printed out the number two in a word, and then the program finished.
Let's do this one more time.
This time I'm going to type in five and five means something else.
So none of the first three conditions were true.
So we went down to the fallback condition, which was line 14.
Of course, for these comparison operators, you can use other as well, not just the equality operator.
Of course, when you make a comparison as part of an if statement, you're not confined to testing for
a quality, you can test for a lot of other things.
You can have a look at the value comparisons section of the Python three, the limitation.
And you can see that operators such as these are also available to less than greater than is equal operator
quality that we've been playing with.
And then you've got a bunch of others as well.
So if you want to know exactly what kind of value comparisons are possible, have a look at this documentation
here.
And it's a lot of information and examples that can help you with this.
And of course, remember that you can also use a string of comparison operators to, for example, you
can say something like this.
So what this is going to do now is going to check whether this is true and this is true, and if both
of these two expressions and comparisons are true, then the whole expression will become true.
So you can make combinations as well.
And has any number of comparisons evaluated as part of a single statement.