Answer to Question #238165 in Python for C N Manjula

Question #238165
Given an integer n , write a program to print the closest number that has all the even digits.condifer the lowest number if there is same difference between forward and backward numbers.
Input:17
Output:20
Input :-33
Output:-28
1
Expert's answer
2021-09-16T11:36:58-0400
def allDigitsAreEven(number):
    number=abs(number)
    while (number > 0):
        rem = number % 10
        if (rem % 2 != 0):
            return False
        number = int(number / 10)
    return True


number =int(input())
numberCounter1=number
numberCounter2=number


while not allDigitsAreEven(numberCounter1):
    numberCounter1-=1
while not allDigitsAreEven(numberCounter2):
    numberCounter2+=1
    
diff1=number-numberCounter1
diff2=number-numberCounter2


lowestNumber=numberCounter1


if diff1>diff2:
    lowestNumber=numberCounter2
print(lowestNumber)






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