Question

Python Input should be : 122 And output should be :1372

Python
Input should be : 122

And output should be :1372
media%2F635%2F6356b0fe-a024-4e12-83a0-84
0 0
Add a comment Improve this question Transcribed image text
Answer #1
def has_even_digit(n):
    while n > 0:
        d = n % 10
        if d % 2 == 0:
            return True
        n //= 10
    return False


def reverse(n):
    result = 0
    while n > 0:
        d = n % 10
        result *= 10
        result += d
        n //= 10
    return result


def main():
    n = int(input("Enter a number: "))
    while True:
        rev = reverse(n)
        n += rev
        if not has_even_digit(n):
            break
    print(n)


main()

Enter a number: 门.13

\color{red}please\;note\;1372\;contains\;an\;even\;digit(2).\;so,\;output\;is\;not\;1372

\color{red}if\;you\;still\;think\;1372\;is\;output,\;then\;please\;let\;me\;know\;how\;it\;is,\;then\;I\;will\;change\;code!

Add a comment
Know the answer?
Add Answer to:
Python Input should be : 122 And output should be :1372
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT