Answer to Question #266863 in Python for kaavya

Question #266863

closest even digits number:


Given an integer N, write a program to print the closest number that has all the even digits. Consider the lowest number if there is same difference between forward and backward numbers.


Input:


The input is a single line containing an integer N.


Output:


The output should be a single line containing the closest integer , that has all even digits.


Explanation:


In the example, the number is 17. The closest number that has all even digits in it is 20. So the output should be 20.

1
Expert's answer
2021-11-16T05:21:29-0500

Source code

n=int(input("\nEnter a number: "))


def allEven(list1):
    count=0
    for i in list1:
        if(i%2==0):
            count+=1
    if(count==len(list1)):
        return True
    else:
        return False


while True:
    n_s=[int(i) for i in str(n)]
    if allEven(n_s)==True:
        print("\nClosest even digits number:",n)
        break
    n+=1


Output


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS