From the course: Python for Non-Programmers

Solution: Odd or even

- Hopefully your first coder pad challenge went well. Again, what I'd like you to find here is if a number is odd or even, and we're going to use that modulo that I talked about in the previous video to determine that. So I'm going to go ahead and move into the code editing portion here. And what I want to do is first find the remainder of the number divided by two. So I'm going to say remainder, this is a new variable I'm creating, is going to be equal to whatever number is, and then use this modulo. And then the number two. This is saying take the number divided by two, and then whatever the remainder is, that's going to go into that variable called remainder. And I'm just going to go ahead and print this out. So I'm going to print out whatever is inside of remainder and let's see if this is working. So I'm going to test this and I can see there's the number one, right? And if I change the number from seven to six, let's go ahead and test this. It goes to zero, okay. So we can see that this is working. I'm going to move that back to seven, but I just want to test and see if that is working, okay. So now that I have the remainder, which is either going to be zero or one, I then need to to determine whether I'm going to return true or false. So what I can do is I'm looking here and I want to say if the number is odd, then I want to return true. So that means if the number is equal to one. So I'm going to say if space remainder is a double equal sign, remember we got to do that when we're comparing things. If it's equal to one:, and then when I hit enter, it's nice coder pad automatically tabs this over for us. I want to return capital true just like this, okay? Because I'm saying this is an odd number. And then I'm going to do a new line and I'm going to say ELT:. Now this is where coder pad needs a little bit of help. We need to hit the back space here to make sure this is on the same tab spacing as the if. And I'm going to do a new line after ELTs, and I'm going to say, well, if it's not equal to one, that must mean it's equal to zero. So in that case, we are going to return false and we can actually get rid of this return line that we have down here at the bottom. And so let's go ahead and test this out and look at that. We now have returned the correct answer because seven is an odd number and we return true and it's all working, okay?

Contents