-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindevennumbers_from_range.py
More file actions
41 lines (21 loc) · 918 Bytes
/
Findevennumbers_from_range.py
File metadata and controls
41 lines (21 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import math
#Taking input for start of range
m=int(input("Enter value of m: "))
#Taking input for end of range
n=int(input("Enter value of n: "))
print("Given range is:", m, "to", n)
print("The numbers in given range with all digits even are: ")
arr=[] #Creating an empty list
for i in range(m,n+1): #Setting a for loop from m to n
num=i #Taking a variable num to work upon
isValid=True #Setting a boolean variable to True
#Extract each digit of num and check if it is even
while(num!=0):
digit=num%10 #Extracting digit
num=num//10
if(digit%2!=0): #Checking if digit is odd
isValid=False #If odd, then isValid is set to False
break #Breaking loop if odd digit found
if(isValid): #If isValid remains True, then all digits are even
arr.append(i)
print(arr) #Printing the list