On this tutorial you’re going to learn how to build a simple Python Program to determine whether a given number is odd or even.
We will use a modulus operator to check whether a given number is divisible by two without remainder or not If yes the number is even else the number is odd .
Program Instructions summary
- Getting a number from the user
- Checking if number is divisible by 2 without remainder
- If true the number is even else the number is odd
#Getting number from user number = int(input('Enter any number: ')) #Check if number is divisible by 2 without remainder if (number % 2 == 0): print('The number is even') else: print('The number is odd')
Running our Program
kalebu@kalebu-PC:~$ python odd_even.py Enter any number: 33 The number is odd -------------------------------- kalebu@kalebu-PC:~$ python odd_even.py Enter any number: 46 The number is even
Hope you find this post interesting , don’t forget to subscribe to get more tutorials like this
In case of any suggestion or comment , drop it on the comment box and I will reply to you immediately.