Coding

Conditional Statements (if, elif, else) in Python – Beginner Python Tutorial #2

  • 00:00:00 what's up guys and welcome back to the
  • 00:00:02 second video in my Python tutorial
  • 00:00:05 series in this video we will cover
  • 00:00:07 everything you need to know about
  • 00:00:08 conditional statements and pythons so
  • 00:00:11 there are three conditional statements
  • 00:00:13 there's the if statement there's the
  • 00:00:15 elephant which just means else if and
  • 00:00:17 there's the else statement and we use
  • 00:00:20 these statements super frequently when
  • 00:00:22 we're programming to allow our code to
  • 00:00:25 do different things based off of
  • 00:00:27 different conditions so for example if
  • 00:00:29 let's say I wanted certain code around
  • 00:00:32 if a number was greater than a thousand
  • 00:00:34 I could do if number greater than a
  • 00:00:36 thousand do this and then I could do
  • 00:00:39 else if that number is less than 1000 do
  • 00:00:43 some other code I'll push the outline
  • 00:00:46 for this video in the comments so if
  • 00:00:49 you're trying to find a specific thing
  • 00:00:50 look there and also I'll post a cheat
  • 00:00:53 sheet to all the commands we've covered
  • 00:00:55 in this video in the description if you
  • 00:00:58 haven't already make sure to subscribe
  • 00:01:00 so you don't miss any of the future
  • 00:01:01 tutorials but without further ado let's
  • 00:01:03 just jump into this tutorial alright to
  • 00:01:07 begin as always open up sublime text 3
  • 00:01:10 and say V new Python file with the name
  • 00:01:12 something like lesson 2 dot py so in the
  • 00:01:17 last video we went over variables and we
  • 00:01:19 show the things like a equals 1 and then
  • 00:01:22 printing a would give us 1 down here
  • 00:01:26 just wanted to expand upon that and just
  • 00:01:29 mention a couple more advanced things
  • 00:01:31 about it variables real quick goes to I
  • 00:01:34 can print right below it print B and as
  • 00:01:42 you can see 1 & 2 I also want to mention
  • 00:01:44 that you can also like set a new
  • 00:01:46 variable as this was probably shown in
  • 00:01:50 the last video but not maybe explicitly
  • 00:01:51 made clear because a plus B and that
  • 00:01:56 won't give us we print see down here
  • 00:01:59 that will give us 3 because it's 2 plus
  • 00:02:03 1 so yeah you can set variables that
  • 00:02:06 have come
  • 00:02:08 nations of other variable names one
  • 00:02:10 thing that you might not know understand
  • 00:02:12 right off the top right from the start
  • 00:02:14 is that if I did something like a equals
  • 00:02:16 five after this it doesn't change what C
  • 00:02:20 is once C has been set it's pointing to
  • 00:02:24 a concrete number three and this a
  • 00:02:26 equals five doesn't change it so even
  • 00:02:32 though this Phi this a are here now
  • 00:02:34 prints five this B still prints to this
  • 00:02:38 see right here was set to one at the
  • 00:02:41 time it was added and set so it just
  • 00:02:43 prints out three down here so I just
  • 00:02:45 wanted to quickly go over that might
  • 00:02:48 have made since already to you but in
  • 00:02:50 case it didn't I thought it would be
  • 00:02:52 helpful to show that all right so let's
  • 00:02:54 start with conditional statements if
  • 00:02:57 Elif
  • 00:02:58 which means else if and else so will
  • 00:03:03 will do this with the concept of grades
  • 00:03:05 so I mean most people are familiar with
  • 00:03:07 grades zero is the worst hundreds of the
  • 00:03:10 best and you can get anything in between
  • 00:03:12 so we're gonna say we're gonna save a
  • 00:03:15 variable called grade here I'll make
  • 00:03:17 this a little bit bigger and I'm gonna
  • 00:03:20 say like let's say we wanted to print
  • 00:03:22 out different things based on what your
  • 00:03:24 grade was so start off with grade equals
  • 00:03:28 ninety or something like that and we can
  • 00:03:32 write the an if statement that prints
  • 00:03:34 out like you passed if you got over a
  • 00:03:37 seventy let's say so we to do this we
  • 00:03:40 use the statement if grade is greater
  • 00:03:44 than seventy and then you always at the
  • 00:03:48 end in an if statement with a colon and
  • 00:03:51 then I can say print you passed so now
  • 00:03:58 I'm going to run this and you see down
  • 00:04:00 here it says you passed so we can do
  • 00:04:05 this is the greater than sign we can
  • 00:04:07 also do so if I set this to seventy here
  • 00:04:12 it doesn't say I pass so we can also in
  • 00:04:16 addition to the greater than sign we can
  • 00:04:17 do the greater than or equal to sign
  • 00:04:20 you passed a and if you did like 50 here
  • 00:04:25 now it doesn't say that we can also do
  • 00:04:31 instead of the greater than or equal to
  • 00:04:33 sign it's probably a pretty intuitive we
  • 00:04:37 do the less than sign so if grade is
  • 00:04:38 less than 50 or less than 70 well right
  • 00:04:42 you failed
  • 00:04:44 come on do better you failed so this is
  • 00:04:49 the if statement its if then you have an
  • 00:04:52 operator here and then I end with a
  • 00:04:54 colon and then you'll have to make sure
  • 00:04:56 whenever you use an if statement you
  • 00:04:58 have to make sure it's indented properly
  • 00:05:01 so you see how this is indented so on
  • 00:05:03 the screen it's pushed in one one tab so
  • 00:05:09 whenever we're using the Python language
  • 00:05:11 to know if something is inside of it is
  • 00:05:14 whether or not it's indented so right
  • 00:05:18 now I try running this it doesn't work
  • 00:05:20 because the if statement by the nature
  • 00:05:24 how its constructed expects an indented
  • 00:05:26 block so make sure to press tab to put
  • 00:05:30 it inside so whenever you want something
  • 00:05:32 inside you really you really have to be
  • 00:05:35 careful to indent it and I'm always
  • 00:05:37 pressing the tab key when I want to
  • 00:05:39 indent I don't want to use spaces
  • 00:05:40 because it's a little hard to get proper
  • 00:05:44 and it will give you some trouble if
  • 00:05:45 you're mixing spaces with tab so I
  • 00:05:48 recommend pressing the tab key
  • 00:05:50 all right so if grades less than 70 you
  • 00:05:53 failed and we could say something like
  • 00:05:56 if grade is less than or equal to 69 you
  • 00:06:06 failed and if I put this as 70 now or
  • 00:06:11 something like you won't say that so
  • 00:06:13 that's the if statement but you know
  • 00:06:15 what right now it's kind of annoying
  • 00:06:17 because we're printing out you failed
  • 00:06:19 but we're not like we can't print you
  • 00:06:23 passed and you failed in the same little
  • 00:06:25 stanza I guess so that's where the else
  • 00:06:28 statements comes in so we have the if
  • 00:06:31 statement
  • 00:06:31 and we're gonna also want to have the
  • 00:06:33 else statement so that's just whenever
  • 00:06:37 you use the else statement you never use
  • 00:06:38 a condition so you don't like do like
  • 00:06:40 greater than 69 that's for the L if it's
  • 00:06:44 not the else so whatever we use else
  • 00:06:46 just use else and then seem with if you
  • 00:06:50 have to end it with in : so I'm going to
  • 00:06:54 change this up again I'm going to just
  • 00:06:55 change this back to 70 and it changes to
  • 00:06:58 greater than or equal to and I'm going
  • 00:07:01 to change this to 90 right now else so
  • 00:07:06 basically what this is saying is if
  • 00:07:08 grade is greater than or equal to 70
  • 00:07:10 right print you passed and you can write
  • 00:07:18 whatever message you want in here you
  • 00:07:20 can change up grade to be something else
  • 00:07:22 doesn't matter
  • 00:07:22 and then else so what else means in this
  • 00:07:25 case is if grade is greater than or
  • 00:07:27 equal to 70 the else condition would be
  • 00:07:30 everything that's not greater than or
  • 00:07:32 equal to 70 so another way to say that
  • 00:07:35 would be everything that's less than 70
  • 00:07:38 print you failed so 90s as you passed if
  • 00:07:48 I change this to 50 control less control
  • 00:07:51 B you failed I could change this to
  • 00:07:54 something like negative 100 which
  • 00:07:57 wouldn't make sense but it still say you
  • 00:07:59 failed I could change this to something
  • 00:08:00 like a huge number but say you passed
  • 00:08:03 so we also might want to have like so
  • 00:08:08 one thing we'll move towards is how do
  • 00:08:10 we get it to say also whether or not the
  • 00:08:12 greatest ballot maybe we would want to
  • 00:08:14 like handle non ballot grades because
  • 00:08:16 great thought it'd be 2 between 0 and
  • 00:08:18 100 and we'll take care of that in a sec
  • 00:08:20 first before we do that I want to kind
  • 00:08:24 of make specific the elf's if block so
  • 00:08:29 in addition to if we have LF
  • 00:08:35 so maybe I would want to say L if grade
  • 00:08:38 is greater than or equal to 80 friend
  • 00:08:47 you got a a B do better next time
  • 00:08:54 life's actually pretty good let's just
  • 00:08:56 say pretty good job I don't want to hate
  • 00:09:00 on these these are fine totally fine
  • 00:09:01 great good job and I'm also going to
  • 00:09:05 switch this this would be greater than n
  • 00:09:06 equal to 70 I'm gonna make this greater
  • 00:09:08 than equal to 90 just to kind of go from
  • 00:09:11 big to small so it's gonna be you got in
  • 00:09:18 a super I don't know why this facing so
  • 00:09:26 we're definitely that's gonna know some
  • 00:09:27 people make it better all right so now
  • 00:09:32 if I put grade as something like 100 you
  • 00:09:36 got an a super if I made it something
  • 00:09:38 like 85 that would fall into this Elif
  • 00:09:42 block so Ulf block that this is all part
  • 00:09:45 of the same execution flow if that makes
  • 00:09:48 sense
  • 00:09:48 so if I do grade greater than 85 you got
  • 00:09:53 to be pretty good job and the difference
  • 00:09:55 between it falling into that and like
  • 00:09:59 something like 95 is it only executes
  • 00:10:03 one so even though the grade is greater
  • 00:10:05 than 90 and it's also greater than 80
  • 00:10:10 because it's part of this if/elif/else
  • 00:10:13 it's only ever gonna enter one of these
  • 00:10:16 so it enters the first one that it valid
  • 00:10:19 is valid in and if it's not valid in any
  • 00:10:22 condition it will print you failed that
  • 00:10:25 would be the else block so if none of
  • 00:10:27 these evaluate to true so what happens
  • 00:10:31 when you if I was to print something out
  • 00:10:34 like this so if I was just a print grade
  • 00:10:36 is greater than or equal to ninety and I
  • 00:10:41 was just to comment all this out
  • 00:10:43 temporarily when I ran this it would
  • 00:10:47 just say true
  • 00:10:48 so this is the boolean variable that we
  • 00:10:50 talked about in the last the last video
  • 00:10:52 and so if these boolean czar true it
  • 00:10:55 enters it and it enters it if it's
  • 00:10:58 indented and also make sure to have this
  • 00:11:01 : so the difference between the if and
  • 00:11:08 the Elif is that if I change this
  • 00:11:12 instead of L left if like another F if I
  • 00:11:16 ran the 95 again it now enters both of
  • 00:11:19 these so it enters that grade equals not
  • 00:11:21 greater than or equal to 90 and it also
  • 00:11:23 enters greater than equal to and so if
  • 00:11:26 you want it to be separate things and be
  • 00:11:30 able to evaluate to true multiple times
  • 00:11:31 you'd use multiple if statements but if
  • 00:11:34 you only want one thing to ever execute
  • 00:11:36 you'd use if/elif/else okay let's see
  • 00:11:42 what else should we do also we could
  • 00:11:46 switch this up I've showed you greater
  • 00:11:48 than I've showed you less than I should
  • 00:11:49 be greater than equal to I've showed you
  • 00:11:51 less than or equal to another important
  • 00:11:53 one is just equal to and so you might
  • 00:11:57 initially just be like okay let's just
  • 00:12:00 say we got a perfect score and that's
  • 00:12:01 all we care about we were super strict
  • 00:12:04 with come with how we did and only a
  • 00:12:07 hundred was acceptable for us so you
  • 00:12:11 might think to just put if grade is
  • 00:12:15 equal to 100 print this is an acceptable
  • 00:12:20 grade as we're super strict only a
  • 00:12:23 hundred is acceptable acceptable grade
  • 00:12:28 and then I do like else print you are a
  • 00:12:36 failure
  • 00:12:37 yeah just if you didn't get a hundred
  • 00:12:39 you're a failure totally joking but you
  • 00:12:42 get the point just making an example so
  • 00:12:45 it gives me this error down here if
  • 00:12:47 grade equals 100 gives me invalid syntax
  • 00:12:52 so it's like why did it do that
  • 00:12:54 that kind of annoys me why I won't
  • 00:12:56 accept an equal sign it accepts greater
  • 00:12:59 than signs it accepts less than signs so
  • 00:13:01 the thing is
  • 00:13:01 here this is something super important
  • 00:13:04 to remember is that when we set
  • 00:13:06 variables we only use one equal sign so
  • 00:13:09 the one equal sign is reserved for
  • 00:13:11 setting variables if we want to actually
  • 00:13:16 use an equal sign as like an operator to
  • 00:13:19 compare two things we need to use a
  • 00:13:22 double equal sign so now I have if great
  • 00:13:26 equals equals 100 and I'll run that and
  • 00:13:30 as you can see I remember one more time
  • 00:13:34 you are a failure sorry you got a 95 not
  • 00:13:37 good enough even if you read out like a
  • 00:13:39 99.999 it's not equal to 100 so it's
  • 00:13:43 gonna still say you are failure and so
  • 00:13:48 this is equal to and then there's one
  • 00:13:51 more operator you know and that will be
  • 00:13:54 not equals to so if the grade is not
  • 00:13:57 equal to 100 this is very much the same
  • 00:14:01 exact thing but we're just switching
  • 00:14:03 around the order so now it's gonna run
  • 00:14:13 it's going to hit this block so it's not
  • 00:14:16 equal to 100 so this is not equal sign
  • 00:14:21 up exclamation point then the equal sign
  • 00:14:24 is not equals to
  • 00:14:25 so to recap that we have four different
  • 00:14:28 operators we have or what I'm gonna say
  • 00:14:30 four we have less than we have greater
  • 00:14:33 than we have less than or greater then
  • 00:14:37 we do we have less than less than or
  • 00:14:40 equal to greater than greater than or
  • 00:14:43 equal to equal to and not equal to so
  • 00:14:49 remember these operators are super
  • 00:14:50 important and that's the we also went
  • 00:14:54 through the flow of if else if and else
  • 00:14:57 okay let's uh delete that for a second
  • 00:15:00 oh actually one more thing I probably
  • 00:15:03 should go over so we're going to go back
  • 00:15:05 to the greater then example so for a
  • 00:15:11 second we'll do greater than 70 that's
  • 00:15:15 and we'll go back to saying you passed
  • 00:15:19 and else you failed so one thing that's
  • 00:15:27 important to note is that in addition to
  • 00:15:29 using these operators that I'm
  • 00:15:30 highlighting on the screen we can also
  • 00:15:34 use to kind of conjunctive stay I don't
  • 00:15:37 know if that was our word at all to two
  • 00:15:41 words that can combine expressions so
  • 00:15:43 one thing I mentioned before is right
  • 00:15:46 now this would accept the grade one how
  • 00:15:50 many zeros is that I don't know I'm too
  • 00:15:54 stressed out I could pass in okay I'm
  • 00:15:57 actually gonna count 1 billion okay I
  • 00:16:02 passing the grade 1 billion and it still
  • 00:16:04 says he passed I want it to instead say
  • 00:16:06 like this is not about grade so I could
  • 00:16:09 do something like if grade is greater
  • 00:16:15 than 100 print not a valid grade right
  • 00:16:24 and I run that and we'll make this see I
  • 00:16:28 bring both of them that's because this
  • 00:16:29 is an if statement instead of an LF so
  • 00:16:32 now it just says not about grade but
  • 00:16:36 still this doesn't quite fix our
  • 00:16:37 problems so if I typed in negative 100
  • 00:16:40 which no no maybe here you did really
  • 00:16:43 badly the test at me you get negative
  • 00:16:45 100 but that's just gonna say you failed
  • 00:16:48 right now yes but we'd rather just say
  • 00:16:51 the same thing not a valid grade so what
  • 00:16:53 I'm gonna do here is I'm going to use a
  • 00:16:56 statement called or so I'm going to say
  • 00:16:59 if grade is greater than 100 or so or is
  • 00:17:02 an acceptable freeze and Python grade is
  • 00:17:06 less than 0 print not a valid grade as
  • 00:17:12 you can see it says not a valid great
  • 00:17:14 hair so that fix our problem so now I
  • 00:17:17 can type in only valid 0 to 100 numbers
  • 00:17:21 to get you pastor you failed so this
  • 00:17:25 order right here
  • 00:17:27 one thing to note about it I might have
  • 00:17:29 this pop up on the screen I'm not sure
  • 00:17:31 but only one of these things has to be
  • 00:17:35 true so so either a grade has to be
  • 00:17:40 greater than 100 so if I did like a
  • 00:17:42 thousand that's true but grade less than
  • 00:17:45 zero is not true in that case so true or
  • 00:17:48 false works false or true works and then
  • 00:17:52 true and true so like if they're both
  • 00:17:54 true it still passes the there's a
  • 00:17:57 statement also called and so this make
  • 00:18:00 means that both of them have to be true
  • 00:18:03 so right now it says you pass because
  • 00:18:09 and is the improper statement to use
  • 00:18:12 here because I would say grade has to be
  • 00:18:14 on greater than 100 and grade has to be
  • 00:18:16 less than zero okay okay so and means
  • 00:18:21 both have to be true or just means one
  • 00:18:23 has to be true but both can't be true so
  • 00:18:27 that's useful also very useful too now
  • 00:18:29 let's move forward if statements they
  • 00:18:36 don't just work with numbers they also
  • 00:18:38 can work with strings for examples so I
  • 00:18:42 could do something like if let's say our
  • 00:18:46 name so my name as says in the YouTube
  • 00:18:49 description is Keith and make sure you
  • 00:18:52 remember when we were using strings
  • 00:18:54 these are called strings the actual text
  • 00:18:56 is called strings make sure that you
  • 00:19:00 surround them with quotations and it
  • 00:19:02 doesn't matter if you use single or
  • 00:19:04 double quotations both work just fine
  • 00:19:06 but you here's how to be consistent so I
  • 00:19:09 could say something like name equals
  • 00:19:11 Keith if name equals equals Keith then
  • 00:19:19 print let's say will print Wow
  • 00:19:24 what a cool name so run that and what
  • 00:19:31 the heck it didn't work so be careful
  • 00:19:33 when you're comparing strings you have
  • 00:19:35 to make sure that cat
  • 00:19:36 realization is exactly how it is in both
  • 00:19:40 things because this doesn't have the
  • 00:19:42 same capitalization it didn't actually
  • 00:19:43 run this so I'm gonna fix this I'm just
  • 00:19:47 going to say if name equals equals Keith
  • 00:19:49 and there are ways that I'll cover
  • 00:19:50 different in future videos that you can
  • 00:19:53 you can like lowercase every letter in a
  • 00:19:56 word and how just make sure that the
  • 00:19:58 letters are the same that will be in a
  • 00:20:00 video on strings
  • 00:20:03 now it says wow what a cool name so that
  • 00:20:07 worked with strings you could do
  • 00:20:11 something like let's say let's say we
  • 00:20:13 were making a game and we wanted it to
  • 00:20:16 so this have a variable called game over
  • 00:20:20 equals true and I wanted I could say
  • 00:20:24 something like this to game if game over
  • 00:20:29 equals equals true then we want to print
  • 00:20:33 [Applause]
  • 00:20:35 we'll just say like let's say this game
  • 00:20:39 you lost or something right you lost so
  • 00:20:43 if I run that says you lost and this is
  • 00:20:47 called a boolean but one thing to note
  • 00:20:49 with when you're using boolean Ziff you
  • 00:20:51 want to have like the proper coding
  • 00:20:53 syntax or proper Python like convention
  • 00:20:57 is it's redundant to say if game over
  • 00:21:01 equals equals true because game over is
  • 00:21:04 true right and this if statement works
  • 00:21:10 on whether something is true or false so
  • 00:21:12 when I before I'm gonna do it one more
  • 00:21:14 time just to show you guys when I before
  • 00:21:17 did some of them like grade equals
  • 00:21:19 ninety and then I didn't print grade is
  • 00:21:23 greater than or equal to 85 let's say
  • 00:21:27 this whole statement evaluates to true
  • 00:21:30 by itself like so if I did that it
  • 00:21:35 valuates the truth this is printing true
  • 00:21:37 so when I go back and I take this line
  • 00:21:43 here if game over
  • 00:21:48 equals equals true it's redundant to do
  • 00:21:54 equals equals true we should just do if
  • 00:21:57 game over now that still works enough
  • 00:22:01 game over was false because this is
  • 00:22:05 basically saying if game over game over
  • 00:22:08 set to true in the last example and so
  • 00:22:12 it's basically saying if true and
  • 00:22:13 whenever something is true in an if
  • 00:22:15 statement it enters it and it always
  • 00:22:17 remember indents friender I can't do
  • 00:22:19 this
  • 00:22:20 won't be proper syntax cool and also
  • 00:22:27 note that you could have nested if
  • 00:22:32 statements so if we were going back to
  • 00:22:34 our grades example I could say greed
  • 00:22:37 equals 87 let's say I could have a set
  • 00:22:42 of statements that are that look like
  • 00:22:44 this if grade is greater than 80 kind of
  • 00:22:48 long that will go big to small so if
  • 00:22:52 grade is greater than 90 print you got
  • 00:22:56 an A and then Elif great is greater than
  • 00:23:06 Elif greater is greater than 80 prints
  • 00:23:13 you got a B right so I could do that I
  • 00:23:19 run it worked oh shoot what happened
  • 00:23:23 whenever we have a LF we have to have
  • 00:23:26 what is the problem here oh I just said
  • 00:23:29 Elif grade 80 I left created greater
  • 00:23:32 than 80 putting you gonna be and so in
  • 00:23:35 this case it says you gotta be we could
  • 00:23:37 nest if statements with within this LF
  • 00:23:40 so I could say if grade is less than 83
  • 00:23:47 I'll say print you got a b-minus and I
  • 00:23:57 can do the same thing LF grade is
  • 00:24:00 less than will say 86 I will say less
  • 00:24:06 than 87 actually I don't really know
  • 00:24:08 what the technical convention is my high
  • 00:24:11 school actually didn't use letter grades
  • 00:24:13 really at all my college it's a MIT used
  • 00:24:18 mostly numbers – I guess letter grades
  • 00:24:20 on our transcript but it was mostly like
  • 00:24:25 we just had a s B's and C's not a minus
  • 00:24:28 a plus etc L if grade is less than 87
  • 00:24:31 you got a B and then finally else so
  • 00:24:35 that only case because this is saying
  • 00:24:37 greater than 80 and these are all less
  • 00:24:39 than 83 less than 87 the only other case
  • 00:24:42 would be like less than 90 so I don't
  • 00:24:44 even have to ever specifically write
  • 00:24:45 that I can just say print you got a
  • 00:24:49 b-plus alright and now I run this I'm
  • 00:24:57 gonna okay let's see what happens so 87
  • 00:25:00 you got a b-plus I did 81 you got a
  • 00:25:05 b-minus
  • 00:25:06 so I did the if statements within
  • 00:25:08 another set of if statements and that's
  • 00:25:10 totally fine
  • 00:25:12 else I'll just print
  • 00:25:15 you got a C or worse and this wouldn't
  • 00:25:24 handle the those weird cases the above
  • 00:25:26 100 and below zero that I mentioned
  • 00:25:29 previously but cool
  • 00:25:30 that's if statement we've gone over if
  • 00:25:34 stamens we got over L if we've gotten
  • 00:25:35 over ELLs we've gotten over nesting them
  • 00:25:37 we've gone over down here all the
  • 00:25:40 different operators you can have and
  • 00:25:41 then I also just want to explicitly
  • 00:25:43 write out there's the two statements to
  • 00:25:45 combine them and an or also it's worth
  • 00:25:50 mentioning that you can specify the
  • 00:25:52 ordering of these and and or with
  • 00:25:54 parentheses so I'm going to add this to
  • 00:25:55 this little comment so what I mean by
  • 00:25:59 this is if I delete all of this code up
  • 00:26:01 here I could write a statement like this
  • 00:26:03 I got it right if false and false or
  • 00:26:08 true so we have an an statement you need
  • 00:26:13 both things around it or both everything
  • 00:26:15 in the end statement to be true when you
  • 00:26:18 have an or statement need either one or
  • 00:26:21 the other to be true
  • 00:26:22 so we'll do print past or something so
  • 00:26:29 we're gonna see if this goes through and
  • 00:26:32 as you can tell it does go through and
  • 00:26:33 the reason for this one to go through is
  • 00:26:35 because it does if false and false
  • 00:26:37 evaluates that first and that evaluates
  • 00:26:40 to false and then it does if false are
  • 00:26:43 true and has the one true so it a value
  • 00:26:46 eights to true however if I added in
  • 00:26:49 parentheses right here I would do if
  • 00:26:55 false and false or true this would now
  • 00:26:58 evaluate first and false or true becomes
  • 00:27:01 true and now it it runs and it doesn't
  • 00:27:06 pass and I can show you it doesn't pass
  • 00:27:10 so parentheses can be used and are super
  • 00:27:12 important and making sure you have kind
  • 00:27:14 of can group things together that need
  • 00:27:16 to be grouped together and also I
  • 00:27:19 realize the dismiss of one other word
  • 00:27:20 you can also write not so I could do
  • 00:27:23 something like print not true and it'll
  • 00:27:28 just do the reverse of true which is
  • 00:27:30 false I did the same thing with false
  • 00:27:33 not false true and this could be useful
  • 00:27:39 in the case that maybe we were playing a
  • 00:27:41 game and I had game over equals true or
  • 00:27:44 equals false and you wanted something to
  • 00:27:47 happen if not game over you know you
  • 00:27:54 would like have your keep playing code
  • 00:27:56 in the middle here so like keep playing
  • 00:27:59 alright so not and or parentheses all of
  • 00:28:03 this pretty good all right I'm gonna end
  • 00:28:06 this video with a challenge problem I'll
  • 00:28:09 answer this challenge problem in the
  • 00:28:10 next video I post in this series and the
  • 00:28:13 challenged problem is as
  • 00:28:15 all those so I want you guys to try to
  • 00:28:18 figure out if you can set read a set of
  • 00:28:20 conditional statements so if Elif and
  • 00:28:22 Elsa's to find out whether or not a
  • 00:28:25 number is so-called a special number so
  • 00:28:29 and I'm going to define special numbers
  • 00:28:34 so write a set of conditional statements
  • 00:28:36 to find out whether or not a number is a
  • 00:28:38 special number I'll make this a little
  • 00:28:40 smaller so you can see all right a
  • 00:28:43 special number so I'm gonna say that
  • 00:28:47 special numbers are numbers that are
  • 00:28:48 less than 100 or greater than or equal
  • 00:28:53 to 300 and they are perfectly divisible
  • 00:28:57 by 3 7 or both so I'll write that down
  • 00:29:00 here so special numbers are defined as
  • 00:29:04 number is less than 100 or greater than
  • 00:29:05 or equal to 300 that perfectly those
  • 00:29:07 about three silver bowl and I want you
  • 00:29:10 to do the following if it is divisible
  • 00:29:13 by both and it is a special number I
  • 00:29:16 want you to print out divisible by both
  • 00:29:21 if it's just divisible by three and it's
  • 00:29:24 a special number I want you to just do
  • 00:29:28 divisible by three so this is divisible
  • 00:29:30 by 3 but not 7 and then finally the last
  • 00:29:32 one is you I want you to print out
  • 00:29:36 divisible by 7 if it's a special number
  • 00:29:39 divisible by 7 but not 3 and then
  • 00:29:42 finally if it is not less than 100 or
  • 00:29:47 greater than equal to 300 or not
  • 00:29:49 divisible by 3 or 7 I want you to print
  • 00:29:52 out not a special number so this is the
  • 00:29:56 task and I'll put this in the
  • 00:30:00 description so this challenge problem in
  • 00:30:02 the description so try this out and if
  • 00:30:06 you could figure it out post your code
  • 00:30:07 at the comments here and I'll try to get
  • 00:30:10 back to everyone that posts in the
  • 00:30:11 comments on whether or not you are
  • 00:30:12 correct and what you can improve on I'll
  • 00:30:16 also put the answer to this problem in
  • 00:30:18 the start of the next video and if you
  • 00:30:22 want a hint I'll tell it right now if
  • 00:30:24 you don't want the hint just start
  • 00:30:25 trying this problem but here is the
  • 00:30:28 so a hint is if you want to find if
  • 00:30:31 something's perfectly divisible you can
  • 00:30:33 use this % so I covered this in the math
  • 00:30:36 video so if let's say we had number
  • 00:30:39 equals 52 if I wanted to see if that was
  • 00:30:44 perfectly divisible by 2 I could do if
  • 00:30:47 number modulo divided by 2 equals equals
  • 00:30:51 0 print like even so as you can see it's
  • 00:31:02 an even number I switched this like 57
  • 00:31:05 it would not say even and so it's
  • 00:31:08 basically just seeing it's dividing it
  • 00:31:09 by 2 and looking at the remainder this
  • 00:31:11 is just saying if the remainder is 0 so
  • 00:31:13 you can use this with 3 and 7 and that
  • 00:31:16 gets you good start to this problem
  • 00:31:19 alright thank you guys for watching I
  • 00:31:21 hope you learned something as always
  • 00:31:23 make sure to like this video and also
  • 00:31:26 subscribe if you haven't already I'll be
  • 00:31:28 posting the next tutorial video in this
  • 00:31:30 series by next week so stays to stay
  • 00:31:33 tuned for that that's all I got peace