# Even Odd Program in Python

Python program to check given number is an even number or odd number? We will discuss different methods to check number is odd or even. A number will be given to the program and the python program will check the given number is odd or even. We will also find all odd and even numbers in between a given range in Python.

Even number:- A number is called an even number if it is divisible by 2.
Example:- 2, 4, 6, 8 e.t.c. are even numbers because they are completely divisible by number 2.

Odd number:- A number is called an odd number if it is not divisible by 2.
Example:- 1, 3, 5, 7 e.t.c. are odd numbers because they are not completely divisible by number 2.

## Python Program to check if a Number is Odd or Even

This is the simplest and easiest python program to check given number is an odd number or even number. We will take one number while declaring the variables. Python program will check given number is an odd number or even number using mathematical calculation and finally, it will be displayed on the screen.

Program description:- Write a Python program to check number is odd or even?

``````# Python program to check given number is an even or odd

# take inputs
num = 5

# check number is even or odd
if(num % 2 == 0):
print('{0} is an even number'.format(num))
else:
print('{0} is an odd number'.format(num))``````

Output:-

5 is an odd number

In this program, value for the number was hardcoded in the program.

``num = 5``

Then, checked the given number is an odd number or even number using the if-else statement and finally, display the result.

``````if(num % 2 == 0):
print('{0} is an even number'.format(num))
else:
print('{0} is an odd number'.format(num))``````

## Python Odd or Even Program

In the previous program, inputs were hardcoded in the program but in this program, inputs will be provided by the user.

``````# Python program to check given number is an even or odd

# take inputs
num = int(input('Enter a number: '))

# check number is even or odd
if(num % 2 == 0):
print('{0} is an even number'.format(num))
else:
print('{0} is an odd number'.format(num))``````

Output for the different input values:-

Enter a number: 8
8 is an even number

Enter a number: 9
9 is an odd number

Enter a number: 25
25 is an odd number

In this program, inputs are scanned using the input() function and stored in variable num.

``num = int(input('Enter a number: '))``

Then, check the given number is an odd number or even number using the if-else statement and finally, display the result.

## Even odd Program in Python using Functions

We can also take the help of a function to check number is odd or not in python. A function is a block of code that performs a specific task.

``````# Python program to check given number is an even or odd

# Returns true if num is even, else odd
def oddEven(num):
# check number is even or odd
return (num % 2 == 0)

# take inputs
num = int(input('Enter a number: '))

# display result
if oddEven(num):
print('{0} is an even number'.format(num))
else:
print('{0} is an odd number'.format(num))``````

Output for the different input values:-

Enter a number: 10
10 is an even number

Enter a number: 13
13 is an odd number

In this program, first of all a function oddEven() is defined which checks the passed value is an odd number or even number?

``````# Returns true if num is even, else odd
def oddEven(num):
# check number is even or odd
return (num % 2 == 0)``````

Inputs are scanned using the input() function and stored in variable num. Then call the function and print the result condition.

In this program, We will learn how to print odd numbers and even numbers in the given range. Example:- Python program will be print all odd numbers and even numbers in the 5 to 15 number range.

``````# Python program to print all even and odd numbers in given range

# take range
start = int(input('Start: '))
end = int(input('End: '))

for num in range(start, end + 1):
# check number is odd or not
if num % 2 == 0:
print(num, end = ':Even ')
else:
print(num, end = ':Odd ')``````

Output:-

Start: 5
End: 15
5:Odd 6:Even 7:Odd 8:Even 9:Odd 10:Even 11:Odd 12:Even 13:Odd 14:Even 15:Odd

``````# Python program to print all even and odd numbers in given range

# take range
start, end = 1, 100

for num in range(start, end + 1):
# check number is odd or not
if num % 2 == 0:
print(num,end = ':Even ')
else:
print(num, end = ':Odd ')``````

Output:-

1:Odd 2:Even 3:Odd 4:Even 5:Odd 6:Even 7:Odd 8:Even 9:Odd 10:Even 11:Odd 12:Even 13:Odd 14:Even 15:Odd 16:Even 17:Odd 18:Even 19:Odd 20:Even 21:Odd 22:Even 23:Odd 24:Even 25:Odd 26:Even 27:Odd 28:Even 29:Odd 30:Even 31:Odd 32:Even 33:Odd 34:Even 35:Odd 36:Even 37:Odd 38:Even 39:Odd 40:Even 41:Odd 42:Even 43:Odd 44:Even 45:Odd 46:Even 47:Odd 48:Even 49:Odd 50:Even 51:Odd 52:Even 53:Odd 54:Even 55:Odd 56:Even 57:Odd 58:Even 59:Odd 60:Even 61:Odd 62:Even 63:Odd 64:Even 65:Odd 66:Even 67:Odd 68:Even 69:Odd 70:Even 71:Odd 72:Even 73:Odd 74:Even 75:Odd 76:Even 77:Odd 78:Even 79:Odd 80:Even 81:Odd 82:Even 83:Odd 84:Even 85:Odd 86:Even 87:Odd 88:Even 89:Odd 90:Even 91:Odd 92:Even 93:Odd 94:Even 95:Odd 96:Even 97:Odd 98:Even 99:Odd 100:Even

Also See:- Even Number Python Program

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!