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.
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
Comments
Leave a comment