 Okay, continuing this series on Python 3. Today we're going to be looking at detecting whether a number is an even number or an odd number. Okay, so here we go. We're going to write this into a script. Again, I'm going to use Vim as my text editor, use whatever text editor you prefer. Again, make sure it's not a word processor. That would be bad. Also, this is part of a series. There should be an annotation on the screen to the full playlist. So here we go. Vim, I'll call this just even.py. We are going to start off this code as always with our Shebang line. This is important, although not necessary for the code to run proper. It's one of those things that if you're a good programmer, you're going to put this in there because it makes it easier for people to use your code, less likely for things to get screwed up. Okay, so what we need to do, we need to ask the user to enter a number. We'll say x and we're going to say input and we'll say enter a number. And as we've talked about in last tutorials and tutorials before, since this is going to be a number, we want it to be an integer, we are going to put it that within the function of int. So the user enters a string and then we're going to convert it to integer, which is a whole number. Okay, at this point we're going to say if and we're going to say x and we're going to say percent 2. Okay, do you guys remember what that does from our math video that we did weeks and weeks ago? The percent sign is saying find us the remainder. Basically it's dividing the number and finding the remainder. And we're going to say if it equals zero. Well then we're going to print this is an even number. Right? And now what if it's not what if there isn't? Then we can say l if and we could say percent x percent I'm messing up here. 2 equals 1. Because when you're dividing by 2 your remainder should be either 1 or 0. It's either going to divide evenly or it's not. So we're going to say print and we're going to say here this is an odd number. We'll save that. Then we're going to change mods to make it executable and this is once again a script is non executable just like any executable whether it's binary or script should not have permission to run until the user gives it permission. So you could do this and then you can just run the script as is and we'll check the shebang line for the interpreter or you can directly put it into the interpreter which hopefully is already installed and executable on your system. But the point is that the script by itself cannot just run by simple clicking it doesn't have permission unless the user gives it permission to run. So then I do .slash that's just saying .slash means this folder. In this folder run this program even .py. Then we'll say enter a number. I'll enter the number 5 and hit enter and it says that is an odd number. If we run it again and I say 10 it says this is an even number. You know and you can do big numbers you can say blah blah blah and this obviously because you always look at the last digit is an even number so this is an even number. I can go do do do and this by looking at the last digit we already know is an odd number. So I mean a simple code but definitely could become important especially if you ever start working with more advanced things like gaming not that I'm going to get into that with any of these tutorials but you start getting into a lot of number stuff to figure stuff out when you work with gaming so this is definitely something that could be useful if you're planning on going down that avenue down the line. But anyway I'm going to enter the the code again with my text editor Vim and again we'll review here and we'll make some changes to see if certain things make a change. So again our shebang line is just saying this is a Python 3 code making sure it's not running in Python 2 or some other interpreter. It's Python 3 that's the environment we're running in. Okay so we have x equals and we're getting the user input which is a string but converting it to an integer. Now as we said we're finding the remainder of the number when it's divided by 2 and again it can only have one of two remainders when you're dividing by two either one or none. So as I said in a previous tutorial stuff like this this makes sense there's only two options so I can have if and l if but really the same thing which would be shorter is just to put else because it's either going to have no remainder and be even otherwise it's an odd number or they didn't put in a number which would cause an error before this as we looked at in the previous tutorial. So just by changing that I can run this again hitting enter I can type in a number and still get that's an odd number or an even number. So looking at this once again before was definitely good for tutorial purposes and definitely is fine to do in your code I'm just showing you that there are different ways to write code and get the same results it's all depending on you know you have to think out all the options if there was options other than one or zero then this else case wouldn't work because it would accumulate accumulate it would combine two answers that may not be and one may not be an odd number if there was a third option so just wanted to point that out so again I hope that you enjoyed this tutorial looking at figuring out whether numbers even or odd and once again pretty much everything in here is stuff that we've already done in previous tutorials was combining them in different ways to get different results and really what I've taught you so far in these first tutorials of printing stuff to the screen so user input and output so getting user information from user and outputting stuff to the screen writing to a file reading from a file saving stuff to variables and then things like if statements and while loops that is I mean you already know 90% of what you're going to need to know when it comes to programming yeah there's still a whole lot of other stuff you can do but when you write out code even when it's when you start creating way more advanced programs majority of what you're gonna be doing is stuff that we've already done these first what tutorials is this 16 or 17? 17 and the first one wasn't even real tutorial it was introduction so I mean in this little time looking at few of these examples you already have the knowledge if you get these down and you learn them what you've learned these tutorials so far you got in my opinion I mean I don't have exact numbers on this but I would say 90% of what you will need for every code you will ever write in Python so we're gonna keep going we're gonna keep learning stuff we're gonna be looking at aspects of it but even as the code gets bigger or more advanced looking majority of it is gonna be these simple basics that's why it's important to learn the basics first you know so yeah anyway I thank you for watching once again I hope that you do visit my site filmsbychrist.com that's Chris of the K there is a link in the description great place to search through my videos also find links there to social networking stuff my Google Plus page Facebook page Twitter account also a link to the IRC channel there which is a great place to come hang out and become a member of this community and help other people with problems and have them help you so I hope to see you in there and I hope that you have a great day