Python program checks whether a number is odd or even
Python program checks whether a number is odd or even
In this, we discuss two examples First, to check whether a number is odd or even and in the second example you will learn to check if the number entered by the user is equal to or even odd.To understand this example, you must have knowledge of the following Python programming topics:
Introduction to Python
Basics of Python
Python libraries
What is an even and odd number?
Now take a look at how we check whether a number is even or odd in Python Programming.
Example 1: To find even and odd number from the list.
Python Code:
import numpy as np a = np.array([1,2,3,4,5,6,7,8,9]) count = 0while count<=8: if(a[count]%2==0): print(a[count]) print('number is even') else: print(a[count]) print('number is odd') count = count + 1
Output:
1
number is odd
2
number is even
3
number is odd
4
number is even
5
number is odd
6
number is even
7
number is odd
8
number is even
9
number is odd
Example 2: To check whether a number is even or odd input entered from user.
Python Code:
num = int(input('enter any number')) count = 0if(num%2==0): print(num) print('number is even') else: print(num) print('number is odd')
Output:
enter any number 57
57
number is odd
Recommended Post: