Welcome back.
Let's do a fun little exercise, we just got hired by a gaming company and we're creating this wizard
game and this wizard game has the is the magician in the user's profile.
And for now, we'll just set it to false.
We also have is.
And whether this user is an expert at this game, we'll leave it a true for now.
And then, hmm, let's let's do this here.
I want you to check if both or check if magician.
And expert.
And if that's the case, if true, then I want you to print you are a master magician and also I want
you to check.
If magician.
But not expert, if that's the case, I want to just print at least you're getting there.
And then finally, let's do a check that says, if you're not a magician.
I want to say, hmm, well, you need magic powers.
Now, I want you to use what you've learned about logical operators to create this conditional logic,
you can pause the video if you want and try it yourself in a Reppel.
Otherwise, I'm going to keep going with an answer.
But you should be able to solve this fairly easily if you've been following the videos and exercises
so far.
So let's start with the first one where we say you are a master magician, so I'm going to say if.
Is expert and is magician.
I'm going to print you are a master magician, so I'm going to copy that and say print.
You are a master magician, nothing too crazy here, and then next one, I'm going to say.
If or I could even say, well, if if I want and again, this is something that you can decide what
you prefer, I usually like using l if if it's part of the same concept as the first one in this case.
Yeah.
We're we're still trying to figure out what type of user it is.
So we'll use Elif and we'll say L if we want to check if it's a magician.
So that is is magician.
So we're going to check if that's true.
But we also want to check.
If well, not an expert now, how do we do this?
I mean, we could say use Short-circuiting and say is expert and even if this is false.
We can get through here because as magician, short circuit and print this part, Aleece, you're getting
there.
Because the interesting here is that this code block is never going to run if both of these are true,
because in the first half block we're checking that so that as soon as this is true, we're going to
completely ignore the L.F..
So we could do that.
But, hmm, this is a little bit hard to read because I really have to think about it.
If I come back to the code or somebody else looks at my code, it's not clear that unless I comment
that I'm checking if it's magician, but expert because this will never run.
If a magician is false, then that's what they're checking for.
I know it's kind of confusing even saying it.
So I prefer using something like this using and not.
And that reads a lot better, right?
It's it's it makes a lot more sense.
Hey, if this person is an expert and magician, do this.
Otherwise, if this person is magician and not an expert, then print this.
That reads pretty nicely.
And yes, you can do this because remember, not as simply checking and inverting, whatever the boolean
expression is.
So this still evaluates to a boolean that and can check.
All right, let's finish the final one, if you're not a magician, you need magic powers.
So how do we check here?
Well, we can do another él if and say not is.
Magician.
And if I run in like this and say print and we'll just copy here, you need magic powers.
And let's remove the comments for now just so we can see the blocks of code.
And we're going to test our program, hopefully we coded it properly, hopefully there's no bugs, but
let's have a look if I run this.
You need magic powers.
Why is that?
Well.
If magician is false, none of these are going to work.
What if I change this to true and I click run?
All right, I am a master magician because I'm an expert as well as a magician.
What if I turn this to false and I click run?
Hey, at least you're getting there.
I'm a magician, but I'm not an expert yet, I'm still I still need to improve my gameplay.
Now, you may have gotten a different answer than me, and there's many ways to do this, right?
You could have used an L statement he could have used or conditional logic is all about writing code
that makes sense not only to you, but for other people reading your code.
The idea is not to be extremely clever or really worry about short.
Yes, it can be more performant, but a machine is so powerful that just a tiny bit of optimization
there is usually not worth it when you're losing perhaps readability.
So you want to make sure that your code reads like English.
And this is a topic that, frankly, a lot of beginner programmers have a hard time understanding where
they tried to be as clever as possible, write as little code as possible in the shortest possible lines
when instead you want to focus on readability, because a code that is easy to understand is a sign
of a good developer.
And I hope looking at this, you're thinking, yeah, this is this is pretty easy.
I mean, this all makes sense.
But this is not the only way.
Maybe my version of what breeds well is different than yours.
The idea is to each of us, try our best to make our code simple and nice.
And in programming, there is no one right answer.
There are many ways to solve a problem, but the key is to solve it in a simple manner that is readable.
I hope you have fun and I'll see you in the next one.