# discussion

Discussion in 'Python' started by Geo_subodh, Oct 1, 2010.

1. ### Geo_subodhGuest

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.

Geo_subodh, Oct 1, 2010

2. ### Roy SmithGuest

In article
<>,
Geo_subodh <> wrote:

> 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?

Roy Smith, Oct 1, 2010

3. ### John NagleGuest

On 9/30/2010 7:12 PM, Geo_subodh wrote:
> 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

John Nagle, Oct 1, 2010
4. ### Chris RebertGuest

On Thu, Sep 30, 2010 at 7:12 PM, Geo_subodh <> wrote:
> 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
--
Relevant, Entertaining, and Groan-inducing!:
http://plzsendmethecode.blogspot.com/

Chris Rebert, Oct 1, 2010
5. ### Paul RubinGuest

John Nagle <> writes:
> def ispalin(s) :
> s = str(s)
> n = len(s) / 2
> return(s[:n] == s[::-1][:n])

def ispalin(s):
return (s == "You betcha!")

;-)

Paul Rubin, Oct 1, 2010
6. ### Arnaud DelobelleGuest

John Nagle <> writes:

> On 9/30/2010 7:12 PM, Geo_subodh wrote:
>> 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

--
Arnaud

Arnaud Delobelle, Oct 1, 2010
7. ### Steven D'ApranoGuest

On Thu, 30 Sep 2010 19:12:06 -0700, Geo_subodh wrote:

> 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")

--
Steven

Steven D'Aprano, Oct 1, 2010
8. ### BartCGuest

"Geo_subodh" <> wrote in message
news:...
> 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)

--
Bartc

BartC, Oct 1, 2010