python count odd numbers in list code example

Example 1: program to find even numbers in python

m = int(input("Enter number"))
if m % 2 == 0:
    print(m,"is an even number")
else:
    print(m,"is an odd number")

Example 2: get a list of even numbers in python

num_range = 10
even_numbers = [num for num in range(num_range) if num % 2 == 0]
# returns: [0, 2, 4, 6, 8]
# to include 10 in the output do
even_numbers = [num for num in range(num_range + 1) if num % 2 == 0]

Example 3: how to get odd numbers in python

# Here, rnge means range
rnge = int(input("Enter the range: "))
for i in range(1, rnge, 2):
    print(i)