python find 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]