Python Simple Odd and Even number

Find whether the given number is Odd or Even

If you divide a number by 2 and it gives a remainder of 0 then it is known as an even number and if you divide a number by 2 and it gives a remainder of 1 then it is known as an Odd number.

 

Example

2%2 == 0 #remainder is 0 so it is even number.

4%2 == 0 #remainder is 0 so it is even number. 

6%2 == 0 #remainder is 0 so it is even number.

8%2 == 0 #remainder is 0 so it is even number.

10%2 == 0 #remainder is 0 so it is even number.

12%2 == 0 #remainder is 0 so it is even number.

134%2 == 0 #remainder is 0 so it is even number.

Note: The number which has the last digit is (0,2,4,6,8) then we can say that is Even numbers. In Python 0 (False).

1%2 ==1 #remainder is 1 so it is odd number.

3%2 == 1 # remainder is 1 so it is odd number.

5%2 == 1 # remainder is 1 so it is odd number.

7%2 == 1 # remainder is 1 so it is odd number.

9%2 = =1 # remainder is 1 so it is odd number.

11%2 == 1 # remainder is 1 so it is odd number.

13%2 == 1 # remainder is 1 so it is odd number.

245%2 == 1 # remainder is 1 so it is odd number.

Note: The number which has the last digit is (1,3,5,7,9) then we can say that is Odd numbers. In Python 1 (True)

Python Program to Count Odd and Even Number in a List

Example

number = [1,2,3,4,5,6,8,9]
odd_count,even_count=0,0
for i in number:
if (i%2==0):
even_count += 1
else:
odd_count += 1
print("odd numbers in the lists :", odd_count)
print("even number in the lists :",even_count)

Output:

C:\Users\Pramod\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/Pramod/PycharmProjects/pythonProject/main.py
odd numbers in the lists : 4
even number in the lists : 4

Process finished with exit code 0

Recommended Post:

Get Salesforce Answers

Pramod Kumar Yadav is from Janakpur Dham, Nepal. He was born on December 23, 1994, and has one elder brother and two elder sisters. He completed his education at various schools and colleges in Nepal and completed a degree in Computer Science Engineering from MITS in Andhra Pradesh, India. Pramod has worked as the owner of RC Educational Foundation Pvt Ltd, a teacher, and an Educational Consultant, and is currently working as an Engineer and Digital Marketer.



Leave a Comment