The Next Palindrome number

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

    def next_palin_drome(n):
        while True:
            n+=1
            if str(n) == str(n)[::-1]:
                return n 
    
    n=12231
    print(next_palin_drome(n))
    

    output:12321

提交回复
热议问题