python even numbers in a 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: recursive python program to print numbers from n to 1
n = int(input())
def rec(n):
if n==0:
print(0)
else:
print(-n)
rec(n-1)
print(n)
rec(n)
Example 3: get a list of even numbers in python
num_range = 10
even_numbers = [num for num in range(num_range) if num % 2 == 0]
even_numbers = [num for num in range(num_range + 1) if num % 2 == 0]
Example 4: python 3 numbers of a range is even
def check(element):
return all(ord(i)%2 == 0 for i in element)
lst = [str(i) for i in range(1000,3001)]
lst = list(filter(check,lst))
print(",".join(lst))