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:
- Python Hello World Program
- Python Comment | Creating a Comment | multiline comment | example
- Python Dictionary Introduction | Why to use dictionary | with example
- How to do Sum or Addition in python
- Python Reverse number
- find the common number in python
- addition of number using for loop and providing user input data in python
- Python Count char in String
- Python Last Character from String
- Python Odd and Even | if the condition
- Python Greater or equal number
- Python PALINDROME NUMBER
- Python FIBONACCI SERIES
- Python Dictionary | Items method | Definition and usage
- Python Dictionary | Add data, POP, pop item, update method
- Python Dictionary | update() method
- Delete statement, Looping in the list In Python
- Odd and Even using Append in python
- Python | Simple Odd and Even number
Get Salesforce Answers