discussion

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

  1. Geo_subodh

    Geo_subodh Guest

    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
    #1
    1. Advertising

  2. Geo_subodh

    Roy Smith Guest

    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
    #2
    1. Advertising

  3. Geo_subodh

    John Nagle Guest

    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
    #3
  4. Geo_subodh

    Chris Rebert Guest

    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
    #4
  5. Geo_subodh

    Paul Rubin Guest

    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
    #5
  6. 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
    #6
  7. 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
    #7
  8. Geo_subodh

    BartC Guest

    "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
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Geno

    Discussion

    Geno, Jul 18, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    528
  2. mohammed rafi

    a discussion about verification

    mohammed rafi, Aug 14, 2004, in forum: VHDL
    Replies:
    12
    Views:
    857
    Andy Freeman
    Aug 21, 2004
  3. ALuPin

    Discussion "Async Reset"

    ALuPin, Oct 25, 2004, in forum: VHDL
    Replies:
    2
    Views:
    670
    Raghavendra
    Oct 27, 2004
  4. charles

    Re: Discussion Forum Application

    charles, Aug 25, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    401
    Nedu N
    Aug 25, 2003
  5. vasss_n
    Replies:
    1
    Views:
    966
    Krissy
    Aug 26, 2003
Loading...

Share This Page