Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

With the help of python, I'm trying to reverse an integer and determine whether it is palindrome or not. Below, you can see my code where I defined the reverse and palindrome method. Is that correct?

def reverse(num):

    s=len(num)

    newnum=[None]*length

    for i in num:

        s=s-1

        newnum[s]=i

        return newnum

def palindrome(num):

    a=str(num)

    l=len(z)/2

    if a[:1]==a[-1:][::-1]:

        b=True

    else:

        b=False

I also have some trouble to type def main.

1 Answer

0 votes
by (26.4k points)
edited by

Try the following code:

def palindrome(num):

    return str(num) == str(num)[::-1]

Searching for a good python tutorial? Join the python course fast.

Watch the below video tutorial on how to become a professional in python

Browse Categories

...