All language subtitles for 8. Exercise Logical Operators

af Afrikaans
sq Albanian
am Amharic
ar Arabic Download
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian Download
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 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,840 --> 00:00:16,220 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,830 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:10,240 And also I want you to check if magician but not expert if that's the case I want to just print. 13 00:01:10,630 --> 00:01:15,060 At least you're getting there. 14 00:01:15,130 --> 00:01:28,000 And then finally let's do a check that says if you're not a magician I want you to say well you need 15 00:01:28,360 --> 00:01:32,330 magic powers. 16 00:01:32,520 --> 00:01:40,280 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,460 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,970 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,850 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,960 So that is is magician. 31 00:02:59,960 --> 00:03:02,410 So we're going to check if that's true. 32 00:03:02,870 --> 00:03:09,170 But we also want to check if well not an expert. 33 00:03:09,230 --> 00:03:11,370 Now how do we do this. 34 00:03:11,390 --> 00:03:20,960 I mean we could say use short circuiting and say is expert and even if this is false. 35 00:03:21,880 --> 00:03:28,510 We can get true here because as magician short circuit and print this part. 36 00:03:28,520 --> 00:03:29,720 Elise you're getting there 37 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 38 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 39 00:03:48,220 --> 00:03:58,150 ignore the L F so we could do that but this is a little bit hard to read because I really have to think 40 00:03:58,150 --> 00:03:58,650 about it. 41 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 42 00:04:04,600 --> 00:04:14,800 I'm checking if it's magician but not expert because this will never run if his magician is false then 43 00:04:15,340 --> 00:04:16,570 that's what they're checking for. 44 00:04:16,570 --> 00:04:28,110 I know it's kind of confusing even saying it so I prefer using something like this using and not and 45 00:04:28,120 --> 00:04:29,800 that reads a lot better right. 46 00:04:29,800 --> 00:04:32,760 It's it's it makes a lot more sense. 47 00:04:32,890 --> 00:04:36,460 Hey if this person is an expert and magician do this. 48 00:04:36,460 --> 00:04:43,430 Otherwise if this person is magician and not an expert then print this. 49 00:04:43,690 --> 00:04:45,110 That reads pretty nicely. 50 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 51 00:04:51,670 --> 00:04:51,880 is. 52 00:04:52,060 --> 00:04:58,460 So this still evaluates to a Boolean that and can check. 53 00:04:58,480 --> 00:05:00,020 All right let's finish the final one. 54 00:05:00,040 --> 00:05:03,070 If you're not a magician you need magic powers. 55 00:05:03,070 --> 00:05:05,050 So how do we check here. 56 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 57 00:05:18,330 --> 00:05:19,510 just copy here. 58 00:05:19,620 --> 00:05:21,210 You need magic powers 59 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 60 00:05:30,080 --> 00:05:32,990 our program hopefully we coded it properly. 61 00:05:33,050 --> 00:05:36,590 Hopefully there's no bugs but let's have a look. 62 00:05:36,620 --> 00:05:41,590 If I run this you need magic powers. 63 00:05:41,620 --> 00:05:42,460 Why is that. 64 00:05:42,460 --> 00:05:47,430 Well if magician is false none of these are going to work. 65 00:05:47,430 --> 00:05:52,060 What if I change this to true and I click Run. 66 00:05:52,080 --> 00:05:52,890 All right. 67 00:05:52,890 --> 00:05:57,900 I am a master magician because I'm an expert as well as a magician. 68 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. 69 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. 70 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. 71 00:06:16,860 --> 00:06:23,980 You could have used an L statement you could have used or conditional logic is all about writing code 72 00:06:24,280 --> 00:06:29,190 that makes sense not only to you but for other people reading your code. 73 00:06:29,200 --> 00:06:35,320 The idea is not to be extremely clever or really worry about short circuiting. 74 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 75 00:06:41,500 --> 00:06:47,010 is usually not worth it when you're losing perhaps readability. 76 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 77 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 78 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 79 00:07:07,960 --> 00:07:14,690 because a code that is easy to understand is a sign of a good developer. 80 00:07:14,920 --> 00:07:19,570 And I hope looking at this you're thinking yeah this is this is pretty easy. 81 00:07:19,570 --> 00:07:23,950 I mean this all makes sense but this is not the only way. 82 00:07:23,980 --> 00:07:28,150 Maybe my version of Y reads well is different than yours. 83 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. 84 00:07:34,750 --> 00:07:36,820 There is no one right answer. 85 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. 86 00:07:45,030 --> 00:07:47,220 I hope you have fun and I'll see you in the next week. 8558

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.