Velocity Reviews > discussion

# discussion

Geo_subodh
Guest
Posts: n/a

 10-01-2010
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.

Roy Smith
Guest
Posts: n/a

 10-01-2010
In article
<(E-Mail Removed)>,
Geo_subodh <(E-Mail Removed)> 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?

John Nagle
Guest
Posts: n/a

 10-01-2010
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

Chris Rebert
Guest
Posts: n/a

 10-01-2010
On Thu, Sep 30, 2010 at 7:12 PM, Geo_subodh <(E-Mail Removed)> 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/

Paul Rubin
Guest
Posts: n/a

 10-01-2010
John Nagle <(E-Mail Removed)> writes:
> def ispalin(s) :
> s = str(s)
> n = len(s) / 2
> return(s[:n] == s[::-1][:n])

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

Arnaud Delobelle
Guest
Posts: n/a

 10-01-2010
John Nagle <(E-Mail Removed)> 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

Steven D'Aprano
Guest
Posts: n/a

 10-01-2010
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

BartC
Guest
Posts: n/a

 10-01-2010
"Geo_subodh" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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