PDA

View Full Version : Palindrome program using Python Programming




sammysam52
Apr 24, 2011, 01:52 PM
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:)



balamw
Apr 24, 2011, 01:59 PM
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.

B

chown33
Apr 24, 2011, 02:03 PM
Did you try googling the obvious: palindrome python program

One of the top 10 hits is this:
http://forums.macrumors.com/showthread.php?t=861800

balamw
Apr 24, 2011, 02:13 PM
Did you try googling the obvious: palindrome python program

One of the top 10 hits is this:
http://forums.macrumors.com/showthread.php?t=861800

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

What is your approach?

B

lee1210
Apr 24, 2011, 03:41 PM
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)
OR
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:
http://www.python.org/doc/

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.

-Lee

KnightWRX
Apr 24, 2011, 05:10 PM
Did you try googling the obvious: palindrome python program

One of the top 10 hits is this:
http://forums.macrumors.com/showthread.php?t=861800

nstead this sounds like an academic assignment/exercise/what-have-you.

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.

balamw
Apr 24, 2011, 05:28 PM
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.

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.

B