discussion

G

Geo_subodh

please send me the simple python code that uses input number greater
than3 digits(>3 digits) and checks whether the number is palindrome
or not.
 
R

Roy Smith

Geo_subodh said:
please send me the simple python code that uses input number greater
than3 digits(>3 digits) and checks whether the number is palindrome
or not.

What class is this for?
 
J

John Nagle

please send me the simple python code that uses input number greater
than3 digits(>3 digits) and checks whether the number is palindrome
or not.

def ispalin(s) :
s = str(s)
n = len(s) / 2
return(s[:n] == s[::-1][:n])

Please use a message subject that describes the content of the message.


John Nagle
 
C

Chris Rebert

please send me the simple python code that uses input number greater
than3 digits(>3 digits) and  checks whether the number is palindrome
or not.

Do your own homework; it's not like you're even paying us (not that we
would have the moral turpitude to be accessories to academic
misconduct anyway).

If you're having trouble, ask a *specific question* rather than
childishly saying "PLZ SEND ME THE CODE!".

Cheers,
Chris
 
A

Arnaud Delobelle

John Nagle said:
please send me the simple python code that uses input number greater
than3 digits(>3 digits) and checks whether the number is palindrome
or not.

def ispalin(s) :
s = str(s)
n = len(s) / 2
return(s[:n] == s[::-1][:n])

return s.startswith(s[n:][::-1])

You'll save valuable time when deploying your palindrome checking system
and it has to check trillions of palindromes an hour :)
 
S

Steven D'Aprano

please send me the simple python code that uses input number greater
than3 digits(>3 digits) and checks whether the number is palindrome or
not.

def is_palindrome_or_not(n):
"""Checks whether the input number n is a palindrome or not."""
if n >= 100:
return n is "palindrome" or n is not "palindrome"
else:
raise ValueError("n must be a positive number with 3+ digits")
 
B

BartC

Geo_subodh said:
please send me the simple python code that uses input number greater
than3 digits(>3 digits) and checks whether the number is palindrome
or not.

The following works without using strings (although leading zeros are
ignored, so that 01210 returns False):

def fpalindrome(n):
if n<0: return False
if n<10: return True

digits=1
a=n
while a>=10:
digits=digits+1
a=a//10

lastdigit=n%10
firstdigit=n//(10**(digits-1))

if firstdigit!=lastdigit: return False
if digits==2: return True

middledigits=n//10-firstdigit*(10**(digits-2))

return fpalindrome(middledigits)

print fpalindrome(12345678987654321)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top