We're going to take a break from replit and talk
a little bit about algorithms because believe it or not,
we're actually going to start working with
slightly more advanced concepts in Python programming.
And it's very, very important for you
to understand what algorithms are because they are vital,
not just for Python but any kind of programming language for that matter.
Now, if I was to give you kind of like the standard definition of what an algorithm is,
it's basically just like a set of instructions
that need to be followed in order to arrive at a particular result.
OK.
In this case, right now, you can see this text, I have written some stuff there.
The very first statement says if
the computer is running fast,
finish.
Now, what do I mean here?
I'm simply saying that look, if our computer is performing very, very well,
it's running very, very quickly.
There is no need to check for anything, it's fine, right? That's why I said finish.
But then notice on the third line, I said
you could also say something like but
right? But in programming language
we don't use but we use,
all right.
So
basically is signifying that if the previous statement is not correct.
So if the computer isn't running fast,
ok, then what do we now need to do?
We need to, first of all check if there is a virus
and then after that, we might need to uninstall unnecessary programs
and then we might eventually need to increase the ramp.
So if we follow these three steps, a
computer
will be guaranteed to run faster.
This is a go with him, right? And two keywords here are the if
and else
we're going to be working with this quite a lot in
this course.
And if you are ever going to work with a different kind of programming language,
you will always come across if else, statements,
these are fundamental building blocks of any program.
I hope you understand what we did here
pretty straightforward.
I'm gonna
make this just a little bit more advanced. Ok. Just a little bit. All right.
Let me open up the
second tab.
So
imagine you're getting dressed based on the weather.
Ok. So
the very first statement we've established a scenario, right?
So our program is checking to see
what we should wear based on the weather.
So
we have the very first result
if the weather is sunny.
Ok. Well, we can wear our sunglasses.
However,
notice the third line it goes else if
it's no longer just else,
why?
Well, because the weather can come in various forms,
it could be sunny, it could be rainy, it could be snowing, it could be cloudy.
There's a lot more options. Right. In the very first document here,
there are only two conditions. The first condition is, is the computer running fast
or is it not running fast?
That's it.
Nothing
like. Is the computer running at 25% capacity? Is it running at 50% capacity?
We don't have any other conditions. It's just to
either the company is running fast or it isn't. It's either A or B
that's why if else would work perfectly here.
However, in this example, we have more than two options
because again, we're dealing with the weather.
So
if it's sunny,
we can wear our sunglasses.
Else if it's raining,
ok, we can take an umbrella
and then else if it's snowing,
we can put on a heavy coat,
right?
But now look at the very last line, it simply says else,
not else if else
because basically we are concluding
the program here.
We're saying, ok, we've checked, if it's sunny, we've checked, if it's raining,
we've checked if it's snowing.
So if it's none of these three
is going to be just a normal day, so else
just dress normally.
Ok.
So
the very first one here again is simply if else because there are two conditions.
The second one here, we do have the else if statement because
there is more than two conditions.
In fact, there are four different results based on the weather.
That's why we can no longer just work with the if else we have to introduce the
if statement.
So hopefully, you understand
why we use the if else statement in here and why we used else if in here,
if you don't, maybe hopefully once we begin to create actual programs
using the algorithms, you will understand it much better then.
But this has been an introduction to the world of algorithms as well as the if else,
if statements.
Thank you for watching. I will see you in the next class.