Hello.
Welcome back.
In this lesson we shall take a look at conditions and loops.
So this was our last lesson.
We can create a new script by clicking follow here.
New file and then we are going to press control and as to save and save.
This is number four on this score.
Conditions conditions on the score loops like this.
Once that's done we conclude this one over here.
Open this a bit right.
So let's see how to create some loops and conditions.
Let's start with a simple example I'm going to declare a string let's say city of course I call this
city London like this and I could see it down here.
Temperature
equals 35.
I could say something like this and over here I could come and see the first condition.
So like in any program language condition uses the if statement in Python we say if city and then we
compare city to what we want to compare to equal to equal to then report the second operant which is
London.
And can we use and it and D.
And here we don't use the undersigned sign.
So we say if city course London and term preacher
because in course 35.
So this condition reads.
If city of course London and temperature equals that 5.
If this condition is true we put column hit Enter colon enter and then what we want to execute if this
condition is true we can say then print
it is hot in London today.
Something like that.
I could just see it as hope in London today
like this and if we want to put an L statement we go out of the indentation.
Come back here and see L's put a semicolon hit enter an imprint.
Something like
it's just fine.
How about that.
It's
just fine like this.
So let's try this out and see what we get currently.
Temperatures that 5 and the cities London.
So the condition should be true we should get this first statement of press control as to save quick
run run module.
This is what we get.
It is hot in London today.
That's how I changed the temperature to 30 control s run run module.
It's just fine.
So this how to create a simple condition if you operations comparison here.
If you want to use and you type and a n d and then this lets look at another operator.
That's the word in I n the operator.
In fact I'll put a comment here to an operator.
We're going to look at this.
OK so let's do another example let's say city cores hobo.
A place like Mumbai.
This is city course Mumbai and we can see if city in and what we have to do here what we're going to
do it is create a list of cities actually.
So to create a list of cities we can just see if city in and then in these cities we are about right.
New York comma Accra through this one in through Istanbul
come out with through London.
Others.
This is enough typing.
So if city in New York Accra Istanbul right.
If if Citi in this list of cities will personally call on a friend
city phoned.
Put exclamation here like this one.
No statesmanship.
Else
semicolon.
Print city not font right.
So let's run this and see this condition will be checked if temperature indeed is equal to 55.
We're going to receive.
Hot in London if not if that's not the case it's going to say it's just fine.
So we're going to see one of these statements printed after that.
This condition would check us well and we'll find whether city found or city not found.
So let's click here to run and see what we've got.
Click okay.
It's just fine because temperature indeed it's not.
That's five cities no phone because city here which is Mumbai it's not in this list and to show you.
Let's just put Mumbai here.
Control s click over here.
Run module and now he says city found.
So this very simple.
This is very simple with such this entire list just by this simple line of code and these five strings
right we didn't need to do any special stuff.
OK.
Let's see on that example how about rather than having the list of the list over here.
Let's throw the list in a variable and then such that list that variable and then see if it produces
the same result.
OK.
I'm going to come down here and see countries
because
two key
Kano
China
and let's through in India here.
And we can come here and see concrete.
Perhaps the country we're looking for is Turkey like this.
So it's the same example.
This time we can see if country
in countries
print
country found.
Remember now we've got both of them represented in variables.
So we've got this list of countries stored in this variable called countries and then we've got this
single country variable which Turkey is assigned to.
We've seen if country in countries meaning if country if Turkey in this list then print country found.
So let's see what we have
or just click here to run and indeed country found.
Right.
So this is how to use conditions and loops.
Very simple.
We shall see more examples as we get to them.
The other variations which we or touch on but this the basics this all you need to know at this point.
So do you have any questions at all.
Just send me a message and I'll get back to you very quickly.
And if you're enjoying the course please take some time off to leave a review that's all there is for
now and have a good day.