Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > discussion

Reply
Thread Tools

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.
 
Reply With Quote
 
 
 
 
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?
 
Reply With Quote
 
 
 
 
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
 
Reply With Quote
 
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/
 
Reply With Quote
 
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!")


 
Reply With Quote
 
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
 
Reply With Quote
 
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
 
Reply With Quote
 
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mozilla Talk Discussion Group graeme@invalid Firefox 6 11-19-2004 02:37 AM
Discussion "Async Reset" ALuPin VHDL 2 10-27-2004 04:03 AM
a discussion about verification mohammed rafi VHDL 12 08-21-2004 08:24 PM
Discussion Geno ASP .Net 0 07-17-2004 11:39 PM
discussion archive Abid Ghufran Cisco 2 12-22-2003 12:21 PM



Advertisments