How to Print a Palindrome of Number In Python

palindrome is the number which is written same from from positon or from back position

ex : 121 or 12321 they will be written same from back or from front

operators used ::
  • % (modulus) which gives us remainder : 32 % 10 = 2 (output)
  • // (integer division) it eliminates quotient after the point  : 121 // 10 = 12 by eliminating 0.1 from the output , normal division would have given us 12.1 .


# code

 a = "123456789"  #input as string as we have to traverse

for i in range(len(a)): # loop executes length of "a" times

    c = int(a) % 10  # gives us number  in the form of remainder from back
    d = int(a) // 10  # eliminates number from the front, in quotient
    a = d                 # substitutes number for further division


    print(c, end="")





output 







Comments