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