‫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 magician in the user's profile and for now we'll just set it to false.
‫We also have is.
‫Expert.
‫And whether this user is an expert at this game.
‫We'll leave it at 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.
‫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 ripple.
‫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 am 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 l 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 live 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 true here because as magician, short circuit and print this part, at least 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 if block we're checking that so that as soon as this is true we're going to completely
‫ignore the LF.
‫So we could do that.
‫But 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 not expert.
‫Because this will never run.
‫If it's 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 bullying
‫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 it 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.
‫You 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 circuiting.
‫Yes, it can be more performant, but a machine is so powerful that just a tiny bit of optimisation
‫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 reads 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.