Search code examples
pythonif-statementfor-looppalindrome

Palindrome in Python


fno = input()
myList = list(fno)
sum = 0
for i in range(len(fno)):
    if myList[0:] == myList[:0]:
    continue
print (myList)

I want to make a number palindrome. eg:

input(123)
print(You are wrong)
input(12121)
print(you are right) 

Please Guide me how to make a palindrome in python.Its not complete code please suggest me what the next step.

Thanks


Solution

  • Slice notation is useful here:

    >>> "malayalam"[::-1]
    'malayalam'
    >>> "hello"[::-1]
    'olleh'
    

    See Explain Python's slice notation for a good introduction.