1 00:00:00,490 --> 00:00:01,070 Welcome back. 2 00:00:01,330 --> 00:00:08,800 Let's do a fun little exercise, we just got hired by a gaming company and we're creating this wizard 3 00:00:08,800 --> 00:00:15,910 game and this wizard game has the is the magician in the user's profile. 4 00:00:16,120 --> 00:00:18,050 And for now, we'll just set it to false. 5 00:00:18,460 --> 00:00:20,500 We also have is. 6 00:00:24,880 --> 00:00:29,800 And whether this user is an expert at this game, we'll leave it a true for now. 7 00:00:30,860 --> 00:00:34,130 And then, hmm, let's let's do this here. 8 00:00:35,820 --> 00:00:43,050 I want you to check if both or check if magician. 9 00:00:44,620 --> 00:00:46,030 And expert. 10 00:00:47,250 --> 00:00:57,960 And if that's the case, if true, then I want you to print you are a master magician and also I want 11 00:00:57,960 --> 00:00:58,950 you to check. 12 00:01:00,030 --> 00:01:03,210 If magician. 13 00:01:05,290 --> 00:01:13,510 But not expert, if that's the case, I want to just print at least you're getting there. 14 00:01:15,030 --> 00:01:22,080 And then finally, let's do a check that says, if you're not a magician. 15 00:01:23,820 --> 00:01:30,990 I want to say, hmm, well, you need magic powers. 16 00:01:32,440 --> 00:01:40,090 Now, I want you to use what you've learned about logical operators to create this conditional logic, 17 00:01:40,310 --> 00:01:44,350 you can pause the video if you want and try it yourself in a Reppel. 18 00:01:44,530 --> 00:01:46,720 Otherwise, I'm going to keep going with an answer. 19 00:01:47,640 --> 00:01:53,100 But you should be able to solve this fairly easily if you've been following the videos and exercises 20 00:01:53,100 --> 00:01:53,570 so far. 21 00:01:55,750 --> 00:02:03,310 So let's start with the first one where we say you are a master magician, so I'm going to say if. 22 00:02:04,380 --> 00:02:09,480 Is expert and is magician. 23 00:02:11,020 --> 00:02:18,580 I'm going to print you are a master magician, so I'm going to copy that and say print. 24 00:02:20,760 --> 00:02:27,210 You are a master magician, nothing too crazy here, and then next one, I'm going to say. 25 00:02:28,890 --> 00:02:36,450 If or I could even say, well, if if I want and again, this is something that you can decide what 26 00:02:36,450 --> 00:02:45,350 you prefer, I usually like using l if if it's part of the same concept as the first one in this case. 27 00:02:45,360 --> 00:02:45,660 Yeah. 28 00:02:45,660 --> 00:02:50,040 We're we're still trying to figure out what type of user it is. 29 00:02:50,040 --> 00:02:55,810 So we'll use Elif and we'll say L if we want to check if it's a magician. 30 00:02:55,830 --> 00:02:59,250 So that is is magician. 31 00:02:59,880 --> 00:03:02,100 So we're going to check if that's true. 32 00:03:02,820 --> 00:03:05,430 But we also want to check. 33 00:03:06,320 --> 00:03:10,460 If well, not an expert now, how do we do this? 34 00:03:11,270 --> 00:03:20,510 I mean, we could say use Short-circuiting and say is expert and even if this is false. 35 00:03:21,820 --> 00:03:29,530 We can get through here because as magician, short circuit and print this part, Aleece, you're getting 36 00:03:29,530 --> 00:03:29,710 there. 37 00:03:33,920 --> 00:03:40,880 Because the interesting here is that this code block is never going to run if both of these are true, 38 00:03:40,880 --> 00:03:47,570 because in the first half block we're checking that so that as soon as this is true, we're going to 39 00:03:47,570 --> 00:03:49,550 completely ignore the L.F.. 40 00:03:50,150 --> 00:03:51,590 So we could do that. 41 00:03:51,890 --> 00:03:58,640 But, hmm, this is a little bit hard to read because I really have to think about it. 42 00:03:58,640 --> 00:04:04,310 If I come back to the code or somebody else looks at my code, it's not clear that unless I comment 43 00:04:04,310 --> 00:04:11,450 that I'm checking if it's magician, but expert because this will never run. 44 00:04:11,450 --> 00:04:16,490 If a magician is false, then that's what they're checking for. 45 00:04:16,520 --> 00:04:19,130 I know it's kind of confusing even saying it. 46 00:04:19,700 --> 00:04:25,280 So I prefer using something like this using and not. 47 00:04:27,850 --> 00:04:29,750 And that reads a lot better, right? 48 00:04:29,770 --> 00:04:32,320 It's it's it makes a lot more sense. 49 00:04:32,860 --> 00:04:35,980 Hey, if this person is an expert and magician, do this. 50 00:04:36,340 --> 00:04:42,910 Otherwise, if this person is magician and not an expert, then print this. 51 00:04:43,660 --> 00:04:45,070 That reads pretty nicely. 52 00:04:45,070 --> 00:04:51,190 And yes, you can do this because remember, not as simply checking and inverting, whatever the boolean 53 00:04:51,190 --> 00:04:51,890 expression is. 54 00:04:52,000 --> 00:04:56,890 So this still evaluates to a boolean that and can check. 55 00:04:58,380 --> 00:05:03,000 All right, let's finish the final one, if you're not a magician, you need magic powers. 56 00:05:03,030 --> 00:05:04,440 So how do we check here? 57 00:05:04,980 --> 00:05:10,890 Well, we can do another él if and say not is. 58 00:05:11,840 --> 00:05:12,440 Magician. 59 00:05:14,800 --> 00:05:21,220 And if I run in like this and say print and we'll just copy here, you need magic powers. 60 00:05:24,290 --> 00:05:28,070 And let's remove the comments for now just so we can see the blocks of code. 61 00:05:29,200 --> 00:05:34,630 And we're going to test our program, hopefully we coded it properly, hopefully there's no bugs, but 62 00:05:34,930 --> 00:05:37,510 let's have a look if I run this. 63 00:05:39,780 --> 00:05:41,350 You need magic powers. 64 00:05:41,580 --> 00:05:42,240 Why is that? 65 00:05:42,420 --> 00:05:42,780 Well. 66 00:05:43,740 --> 00:05:47,310 If magician is false, none of these are going to work. 67 00:05:47,370 --> 00:05:50,130 What if I change this to true and I click run? 68 00:05:51,960 --> 00:05:57,240 All right, I am a master magician because I'm an expert as well as a magician. 69 00:05:57,840 --> 00:06:00,690 What if I turn this to false and I click run? 70 00:06:02,020 --> 00:06:03,790 Hey, at least you're getting there. 71 00:06:04,450 --> 00:06:09,940 I'm a magician, but I'm not an expert yet, I'm still I still need to improve my gameplay. 72 00:06:10,930 --> 00:06:16,860 Now, you may have gotten a different answer than me, and there's many ways to do this, right? 73 00:06:16,890 --> 00:06:24,010 You could have used an L statement he could have used or conditional logic is all about writing code 74 00:06:24,220 --> 00:06:28,580 that makes sense not only to you, but for other people reading your code. 75 00:06:29,200 --> 00:06:34,840 The idea is not to be extremely clever or really worry about short. 76 00:06:35,380 --> 00:06:41,290 Yes, it can be more performant, but a machine is so powerful that just a tiny bit of optimization 77 00:06:41,290 --> 00:06:46,110 there is usually not worth it when you're losing perhaps readability. 78 00:06:47,020 --> 00:06:50,620 So you want to make sure that your code reads like English. 79 00:06:50,770 --> 00:06:58,450 And this is a topic that, frankly, a lot of beginner programmers have a hard time understanding where 80 00:06:58,450 --> 00:07:04,300 they tried to be as clever as possible, write as little code as possible in the shortest possible lines 81 00:07:04,480 --> 00:07:13,000 when instead you want to focus on readability, because a code that is easy to understand is a sign 82 00:07:13,360 --> 00:07:14,410 of a good developer. 83 00:07:14,830 --> 00:07:19,500 And I hope looking at this, you're thinking, yeah, this is this is pretty easy. 84 00:07:19,540 --> 00:07:21,550 I mean, this all makes sense. 85 00:07:21,970 --> 00:07:23,830 But this is not the only way. 86 00:07:23,920 --> 00:07:27,600 Maybe my version of what breeds well is different than yours. 87 00:07:28,120 --> 00:07:33,220 The idea is to each of us, try our best to make our code simple and nice. 88 00:07:33,790 --> 00:07:36,740 And in programming, there is no one right answer. 89 00:07:36,790 --> 00:07:43,600 There are many ways to solve a problem, but the key is to solve it in a simple manner that is readable. 90 00:07:44,920 --> 00:07:47,220 I hope you have fun and I'll see you in the next one.