The Next Palindrome number

前端 未结 11 1753
走了就别回头了
走了就别回头了 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:44

    I have written this for finding next pallindrome number given a pallindrome number.

    def palindrome(num):
        bol=False
        #x=len(str(num))
        num=num+1
        while(bol==False):
            if(check_palindrome(num)):
                bol=True
            else:
                num=num+1
        return num
    def check_palindrome(n):
        temp=n
        rev=0
        while(n>0):
            dig=n%10
            rev=rev*10+dig
            n=n//10
        if(temp==rev):
            return True
    
    b=palindrome(8)
    print(b)
    

提交回复
热议问题