Let's now improve that if structure.
So with what we've seen, we can execute this block of code if that condition is true.
But what if you want to execute a different
set of instructions if the condition is false?
So you want to test if it's true, execute something,
and if it's false, you execute something else.
Well, let's see that.
So first I'm going to come back to the first statement here to make it very simple.
OK.
User age greater or equal than 18, you are an adult.
And then I'm going to come back.
So I press Enter.
And I go back to the first indentation.
And I write else with a color.
I press Enter.
I have a new indentation.
Print you're not an adult yet.
So in this case-- so first is going to check if that is true.
If that is true, it's going to execute the next indented block of code.
And if that is not true-- so if this is false-- we go to the else.
And then we can execute that block of code.
So now let's run this.
OK.
So we still have the same time and end of program.
But you have you're an adult because user age is 30.
Now you're going to put 17.
And you can see you are not an adult yet.
So you can use if and else.
And you can also add intermediate conditions
with else if or in Python it's named elif.
And let's see that with this structure here.
So I'm first going to modify this.
OK.
Because summertime is actually-- so from the north hemisphere--
it's June, July, and August.
OK.
So let's say if month in June, July, August.
So we use the test here to check if one value is in one list.
OK.
So if the value is June or July or August, it's going to work and print summertime.
Let's just test that.
OK.
Summertime.
Now what if I want to test if the month is actually
in the wintertime or the springtime or the Autumn time?
What I can do, I can use elif.
OK.
Not else if.
OK.
Else if can be in other languages.
But for Python, this is going to be elif.
Month in-- let's say we want to test September and then October.
And then November, we can print Autumn time.
So what's going to happen is first, it's going to check that this condition is true.
If yes, it's going to execute that block of code and then exit.
OK.
Once a condition is true, a block of code is executed.
And then the if will exit.
If this is not true, it's going to go to the next
elif, if there is one, and check if that is true.
If that is true, it's going to execute that.
And if it's false, it's not going to execute anything.
And then any of the block here will not be executed.
And we continue the execution here.
OK.
Now I'm going to add another elif.
Month in-- so let's do all the year.
So November, we have December.
And then January.
And then February.
OK.
If the month is in that range, we are going to print wind time.
And then-- so here we still have three months in the year.
OK.
We have March, April, and May.
I could do elif month in March, April, and May.
But I can just do els.
Because, well, that's the only possibility that's left.
So els print spring time.
We first check if that is true.
We print summer time with exit.
If that is false, we check this.
If this is true, we print out on time and exit.
If this is still false, we continue with this.
And if this is true, we print winter time.
If this is still false, we go to the els.
And then we print spring time.
OK.
So we have July, which is summer time.
Let's test with September.
You can see Autumn time.
OK.
Because this is false.
This is true.
So we execute that.
And then we skip all the rest.
Now let's say May.
You can see spring time.
OK.
We are in the pets.
So you can test here with different values.
OK.
To see where you end up in the if structure.
All right.
Now you are able to use if structure to choose
what to execute depending on different conditions.
This will allow you to make your programs much more dynamic.