The Next Palindrome number

前端 未结 11 1750
走了就别回头了
走了就别回头了 2021-01-17 07:23

I am beginner in programming, So can you please tell me what\'s wrong with my code?

I want to print next palindrome number if the number entered by the user (n) is n

11条回答
  •  广开言路
    2021-01-17 07:52

    using function to find next palindrome

    def nearest_palindrome(number):
    if number>0:
        i=1
        while(number):
            n=number+i
            temp=n
            sum=0
            while n>0:
                rem=n%10
                sum=sum*10+rem
                n=n//10
            if temp==sum:
    
                return temp
                #break
            else:
                sum=0
                i=i+1
            #continue
    number=12300
    print(nearest_palindrome(number))
    

提交回复
热议问题