Afrikaans
Akan
Albanian
Amharic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
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 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 you 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 rebel.
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 l if if I want and again this is something
that you can decide what you prefer.
I usually like using elf 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 true here because as magician short circuit and print this part.
Elise 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 F 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 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 his 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 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 then 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 performance 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 Y 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 week.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.