Computer Science, asked by Anonymous, 11 months ago

Write a python program, which will find all such numbers between m and n (both included) such that each digit of the number is an even number Input Format: The first line contains value m and n separated by a comma. Output Format: The numbers obtained should be printed in a comma-separated sequence on a single line. Constraints: 1000<=m<=9000 1000<=n<=9000

Answers

Answered by QGP
10

Here is a Python Program which accomplishes the task.

We take m and n as input.

We then set a loop running from m to n. We extract each digit from each number to see if it is even or not. If the number satisfies the required conditions, we then save it for printing in a list.


Here's the code:


m=int(input("Enter value of m: "))  #Taking input for m

n=int(input("Enter value of n: "))  #Taking input for 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

#We will extract each digit of num and see 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


Attachments:
Similar questions