1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Palindrome program using Python Programming

Discussion in 'Mac Programming' started by sammysam52, Apr 24, 2011.

  1. macrumors newbie

    I am having to write a program that determines whether a number is a palindrome or not using Python Programming. The program uses an input function for the number and then returns the results. All the research I have done has turned out results with Java and other non Python programs. Any help is appreciated. Thank you:)
  2. Moderator


    Staff Member

    Read http://whathaveyoutried.com and http://mikeash.com/getting_answers.html .

    You are unlikely to get the answers you seek without giving us a lot more than you already have. Post any code you have tried that doesn't work. Post links to the Java code that you think does what you want, etc...

    Especially if this sounds like homework, you need to at least try to solve it.

  3. macrumors 603

  4. Moderator


    Staff Member

    For sammysam52, the OP in that thread posted code and solved their own problem with a gentle nudge.

    What is your approach?

  5. macrumors 68040


    I don't really know why research is needed for this, unless you don't know Python at all. If that is the case, you don't need to research how to do this in Python, you just need to research Python. Finding code online that does what you need is easy. However, i doubt somewhat seriously that you have a real-world problem requiring this, and you're simply desperate for a solution. Instead this sounds like an academic assignment/exercise/what-have-you.

    If that is the case, then you want to learn something, not find the answer. That means you might need to learn:
    What a palindrome is (you probably already know this)

    How to write a loop in Python

    How to manipulate numbers using Python (including exponentiation and division, perhaps taking logarithms)
    How to manipulate strings using Python (including getting a substring, string equality, or character equality and getting characters)

    As an academic exercise i would try to write both approaches... treating the number as a number and approaching this with math and treating the number with a string and dealing with it that way.

    I'm confident that you can google your way to what a palindrome is if you don't know, and the Python documentation is actually quite good:

    Good luck. As you progress feel free to post code here telling us what you've tried, what the current errors are (or erroneous results), what you expect to happen, etc. We'll be glad to help you work it out, but it's better for everyone if we don't give you the answer.

  6. macrumors Pentium


    A quick suggestion OP : If this is homework, do not try "googling the obvious" and especially do not copy/paste code from the top 10 hits. If it was that easy to find, your teacher already found it also and will fail you with good reason when you try to turn in "Internet" code.
  7. Moderator


    Staff Member

    That's one of the things that wasn't clear in the OP.

    What is meant by "The program uses an input function for the number and then returns the results." is it supposed to be treated as a number or a string? Is the input part of the code specified in the problem statement?

    Ultimately it doesn't matter since they both reduce to separating the number into digits/characters in either way.


Share This Page