Now we're moving on to conditional statements now you could give conditional statements as an if else
scenario.
For example if you go to the store and you want to purchase a drink and the drink cost two dollars.
Well if you have two dollars you're going to be able to purchase that drink.
If you don't have two dollars then you won't be able to purchase that drink.
That is a condition.
So the condition there is based on the amount of money you have.
We can take these conditional statements and we can run if else we could also run if else if else and
build upon these.
Now it all makes sense when we start putting it together in our script here.
So let's go ahead and just do that let's make a new line and let's make a comment here that says conditional
statements.
And let's start with a conditional statement.
So a conditional statement is going to start off looking like a function.
So we'll say define and here let's make the same scenario where we talked about the money and buying
into ring.
So we'll define drink and we'll just say a parameter here of money.
OK.
And then let's invent and let's say if money is greater than or equal to to me where we talked about
two dollars for this drink then we're going to return.
You've got yourself a drink.
Now what if we don't have the money.
So we could say else if our money is not greater than or equal to two then we're just going to return
no drink for you didn't mean to capitalize the o there but I'm leaving it because I like it.
So in this situation we have our conditions set.
Now again if our money equals or EAP is equal to or greater than two we're gonna get a drink.
And if not we're not going to get a drink.
So it could be anything else.
Right.
So what we can do now is since this is just returning and not printing anything we can print out something
like a drink and then we specify the amount.
So if we have three we should return one thing.
And if we print drink here with only a dollar we should return another.
Let's go ahead and save this script and I didn't put this with an ampersand so I'm going to close out
and make sure I do that next time.
And we're gonna do is we're just going to go ahead and Python 3 script up high and you can see down
here we go back and let me run this script with the ampersand.
You can see that we did a drink of three which we were expecting to return.
You've got yourself a drink.
And we did a drink of one which we're expecting to return no drink for you this happened just the way
we thought it would.
So we can build upon these conditional statements.
Let's talk about a different scenario with multiple parameters.
Let's say that you are an adult and here in the United States if you're an adult and you want to have
a drink of alcohol that requires you to be of age at twenty one.
So in order to purchase alcohol you have to be one of age and to have money.
Now if you don't drink that's perfectly OK.
This is just a example scenario.
So here let's say we wanted to buy alcohol.
We have to meet that age requirement of 21 and we have to meet the requirement of money.
Now we could be in a situation where we meet the age requirement but we don't meet the money or we could
meet the money requirement.
But we don't meet the age requirement or we could be in a situation where we don't meet the age requirement
and we don't meet the money requirement.
So let's set this up to think through this and how these scenarios could play out.
So let's define alcohol here and we need two parameters we're going to say age and money
so first statement here is gonna be our leading if we're going to say if age is greater than or equal
to 21 because we need that condition to be true and our money is greater than or equal to 5.
So let's say a drink cost five dollars we're going to return
we're getting a drink
OK now since we're gonna have multiple conditions here we're going to introduce something called else
if.
Else if here is written like this.
E L I F so else if our age is greater than or equal to twenty one and R money is less than five dollars
then let's return
come back with more money.
We need another else here because we have another condition right.
So we're gonna say whatever our age is less than twenty one and our money is greater than or equal to
five.
Well we're going to return.
Nice try kid because we're not old enough to purchase this drink.
And then lastly and our else scenario if we are not meeting any of the conditions above which means
we won't have the age we won't have the money then we're just going to return here to like a type sorry
you're too poor and too young so let's go ahead and run this a couple different times.
So let's go ahead and print out alcohol and we're going to give our two parameters let's say twenty
one in five let's print out again alcohol and let's give a parameter of twenty one and four and then
let's print out one last time of alcohol and we'll say that we are 20 and four so we should meet a few
different conditions here.
Right.
So at twenty one in five we should return we're getting a drink at 21 and four we should return come
back with more money and at 20 and 4 we should return.
You're too poor and too young.
Now if you want to add in a fourth condition here or a fourth print statement and you want to return
the Nice try kid you're more than welcome to do that as well.
So go ahead.
Hey control ask or save your script out and then let's go ahead and run it
and you can see it we return exactly where we thought we're going to.
We're getting a drink.
Come back with more money and you too poor and too young.
So this is it for conditional statements.
Hopefully this makes sense again our conditions are based on certain items.
Right.
So money here for an example if we have the money we're getting a drink.
If we don't have the money we're not getting a drink and then we can build upon that we have multiple
parameters here.
So if we're not old enough to buy a drink or we don't have enough money to buy a drink or we don't meet
any of these scenarios different things can happen.
Well you need to be thinking about as a developer program or even writing these scripts is all the scenarios
that could happen in these situations you've got to think of the logic behind it.
So when you're building out a script you're building out your first program.
You need to think logically if I make an if statement or a conditional statement what's the logic behind
it.
So a lot of times for example in this scenario we might have thought OK well if I don't have that The
Age or the money OK but you've got to think about what if I do have the age but not the money or I do
have the money but not the age.
So you have to think through everything in your head and make sure that it's all thinking and this just
takes repetition.
And just sitting down the best way is sitting down at the pen and paper and not writing this in code
form but this writing this in a sense that makes sense to you.
Thinking through it logically and then writing it out in code.
So from here we're going to go ahead and move on to list in the next video.
So once you are caught up here let's go ahead and move right over there.