If it's divisible by two well what does it mean to be divisible it means remainder is what right if I do ten divided by two what's my remainder there right so my remainder here will be none because two goes perfectly into ten and there's a way to check for remainders okay so for example let's let's check if 3 goes into 12 right so if my remainder is zero then that means 12 is divisible by 3 right I can also try it like this 12 divisible by 3 and see if this gives me true or false if it gives me true well then 12 is divisible by 3 if it gives me false then 12 isn't divisible by 3 okay so that's your hint I've given you your example here as well and written format and then I have a bonus challenge for you which says if I give you a number and you check that it's you know if it's even and your function checks is even so that for that function the challenge that I gave you is see if you can write it in one line of code okay but don't try that first try to do it with some if-else statement so it's going to get you to do some FL cygnus okay now let's go over the solution so the first thing i want to do is write what's my function name is even okay it says right there is even another thing that you can do to trick the system is if you look at my test notes below well it kind of tells you what the function is called and how its expecting to use the function it's this is how the function is going to be used right you're going to say is even and pass in a number and either it will give you a true or it'll give you a false so I have test cases here written for you if your function runs correctly all these test cases are going to give you a big thumbs up and the screen is going to print out your code is correct all right so let's say that I give this you know some number and basically what do I do if number is divisible by two right that's how you check if it's divisible by two if you just do this that will tell it well that'll give you the remainder so this will evaluate to zero okay but you want something to evaluate either true or false okay so number mod two should give you zero this means that number should be divisible by two that's what it means to be even right two should be able to go inside of that number return true else return false right if two does not go inside of that number perfectly then I should get back false so like if I tested I don't know thirteen divisible by two check if it's divisible it says false well I can even check out what's left over two goes all the way into twelve and then one spills over and you get a remainder of one hence thirteen is an odd Nam not an even number just in case you don't know what I'd and even numbers are zero, two, four, six, eight, ten are all evens and then one, three, five, seven, up to infinity are all odds you can have negative and positive odds or negative and positive evens all right I also have the notes on my website for you guys to help you so remember how to it tells you how to write a function it tells you where to put the colons it tells you to return things and it gives you an example of the add to function as well so let's test it out I'm going to comment out line 43 and I'm going to run this and if it prints out your code is correct then our code is correct otherwise it's wrong okay good it says your code is correct now I'm going to go over the bonus challenge okay so define bonus challenge kind of or actually I can just do it right here because you guys can pause the video and stuff right so you guys can go back in time as well return and what do I want to do number divisible by two is equal to zero and that's it you don't have to do if you don't have to do else it does it all in one go well what happens here if the number is divisible by zero if the number is divisible by two will give you true if it's divisible if it's not divisible by two gives your false so you don't need to check if this then true otherwise false it kind of does that for you so that's your one-liner okay hopefully this video was helpful for you and you learn something in the next video we're going to find out how to find the length of a string so that's a problem that is going to be really cool and you will be able to try it out check out the show notes below so you can practice this and also try to solve this problem the check for even numbers take care
Learn Python Programming - 24 - Check Is Even (Exercise)
"WEBVTTKind: captionsLanguage: enokay guys now let's talk about a new problem alright so I just clicked this part that says check for even number divisibility again if you're on YouTube you're going to have the problem notes below and the solution notes below as well so no need to worry but this is on on clever programmer comm so let's keep going you can write a function or sorry the problem says write a function is even that takes in a number and returns true if it's even otherwise it returns false okay so before you watch the solution take a stab at it and try to do this problem okay and after you're done trying and you're pulling out your hair you're like oh I can't do it come to wash the solution okay I've given you some hints here as well so think about what does it mean for a number to be divisible by another number right so what does it mean let's let's test it out a little bit so if I have 10 and I want to check if it's divisible by two well what does it mean to be divisible it means remainder is what right if I do ten divided by two what's my remainder there right so my remainder here will be none because two goes perfectly into ten and there's a way to check for remainders okay so for example let's let's check if 3 goes into 12 right so if my remainder is zero then that means 12 is divisible by 3 right I can also try it like this 12 divisible by 3 and see if this gives me true or false if it gives me true well then 12 is divisible by 3 if it gives me false then 12 isn't divisible by 3 okay so that's your hint I've given you your example here as well and written format and then I have a bonus challenge for you which says if I give you a number and you check that it's you know if it's even and your function checks is even so that for that function the challenge that I gave you is see if you can write it in one line of code okay but don't try that first try to do it with some if-else statement so it's going to get you to do some FL cygnus okay now let's go over the solution so the first thing i want to do is write what's my function name is even okay it says right there is even another thing that you can do to trick the system is if you look at my test notes below well it kind of tells you what the function is called and how its expecting to use the function it's this is how the function is going to be used right you're going to say is even and pass in a number and either it will give you a true or it'll give you a false so I have test cases here written for you if your function runs correctly all these test cases are going to give you a big thumbs up and the screen is going to print out your code is correct all right so let's say that I give this you know some number and basically what do I do if number is divisible by two right that's how you check if it's divisible by two if you just do this that will tell it well that'll give you the remainder so this will evaluate to zero okay but you want something to evaluate either true or false okay so number mod two should give you zero this means that number should be divisible by two that's what it means to be even right two should be able to go inside of that number return true else return false right if two does not go inside of that number perfectly then I should get back false so like if I tested I don't know thirteen divisible by two check if it's divisible it says false well I can even check out what's left over two goes all the way into twelve and then one spills over and you get a remainder of one hence thirteen is an odd Nam not an even number just in case you don't know what I'd and even numbers are zero two four six eight ten are all evens and then one three five seven up to infinity are all odds you can have negative and positive odds or negative and positive evens all right I also have the notes on my website for you guys to help you so remember how to it tells you how to write a function it tells you where to put the colons it tells you to return things and it gives you an example of the add to function as well so let's test it out I'm going to comment out line 43 and I'm going to run this and if it prints out your code is correct then our code is correct otherwise it's wrong okay good it says your code is correct now I'm going to go over the bonus challenge okay so define bonus challenge kind of or actually I can just do it right here because you guys can pause the video and stuff right so you guys can go back in time as well return and what do I want to do number divisible by two is equal to zero and that's it you don't have to do if you don't have to do else it does it all in one go well what happens here if the number is divisible by zero if the number is divisible by two will give you true if it's divisible if it's not divisible by two gives your false so you don't need to check if this then true otherwise false it kind of does that for you so that's your one-liner okay hopefully this video was helpful for you and you learn something in the next video we're going to find out how to find the length of a string so that's a problem that is going to be really cool and you will be able to try it out check out the show notes below so you can practice this and also try to solve this problem the check for even numbers take careokay guys now let's talk about a new problem alright so I just clicked this part that says check for even number divisibility again if you're on YouTube you're going to have the problem notes below and the solution notes below as well so no need to worry but this is on on clever programmer comm so let's keep going you can write a function or sorry the problem says write a function is even that takes in a number and returns true if it's even otherwise it returns false okay so before you watch the solution take a stab at it and try to do this problem okay and after you're done trying and you're pulling out your hair you're like oh I can't do it come to wash the solution okay I've given you some hints here as well so think about what does it mean for a number to be divisible by another number right so what does it mean let's let's test it out a little bit so if I have 10 and I want to check if it's divisible by two well what does it mean to be divisible it means remainder is what right if I do ten divided by two what's my remainder there right so my remainder here will be none because two goes perfectly into ten and there's a way to check for remainders okay so for example let's let's check if 3 goes into 12 right so if my remainder is zero then that means 12 is divisible by 3 right I can also try it like this 12 divisible by 3 and see if this gives me true or false if it gives me true well then 12 is divisible by 3 if it gives me false then 12 isn't divisible by 3 okay so that's your hint I've given you your example here as well and written format and then I have a bonus challenge for you which says if I give you a number and you check that it's you know if it's even and your function checks is even so that for that function the challenge that I gave you is see if you can write it in one line of code okay but don't try that first try to do it with some if-else statement so it's going to get you to do some FL cygnus okay now let's go over the solution so the first thing i want to do is write what's my function name is even okay it says right there is even another thing that you can do to trick the system is if you look at my test notes below well it kind of tells you what the function is called and how its expecting to use the function it's this is how the function is going to be used right you're going to say is even and pass in a number and either it will give you a true or it'll give you a false so I have test cases here written for you if your function runs correctly all these test cases are going to give you a big thumbs up and the screen is going to print out your code is correct all right so let's say that I give this you know some number and basically what do I do if number is divisible by two right that's how you check if it's divisible by two if you just do this that will tell it well that'll give you the remainder so this will evaluate to zero okay but you want something to evaluate either true or false okay so number mod two should give you zero this means that number should be divisible by two that's what it means to be even right two should be able to go inside of that number return true else return false right if two does not go inside of that number perfectly then I should get back false so like if I tested I don't know thirteen divisible by two check if it's divisible it says false well I can even check out what's left over two goes all the way into twelve and then one spills over and you get a remainder of one hence thirteen is an odd Nam not an even number just in case you don't know what I'd and even numbers are zero two four six eight ten are all evens and then one three five seven up to infinity are all odds you can have negative and positive odds or negative and positive evens all right I also have the notes on my website for you guys to help you so remember how to it tells you how to write a function it tells you where to put the colons it tells you to return things and it gives you an example of the add to function as well so let's test it out I'm going to comment out line 43 and I'm going to run this and if it prints out your code is correct then our code is correct otherwise it's wrong okay good it says your code is correct now I'm going to go over the bonus challenge okay so define bonus challenge kind of or actually I can just do it right here because you guys can pause the video and stuff right so you guys can go back in time as well return and what do I want to do number divisible by two is equal to zero and that's it you don't have to do if you don't have to do else it does it all in one go well what happens here if the number is divisible by zero if the number is divisible by two will give you true if it's divisible if it's not divisible by two gives your false so you don't need to check if this then true otherwise false it kind of does that for you so that's your one-liner okay hopefully this video was helpful for you and you learn something in the next video we're going to find out how to find the length of a string so that's a problem that is going to be really cool and you will be able to try it out check out the show notes below so you can practice this and also try to solve this problem the check for even numbers take care\n"