Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sammysam52

macrumors newbie
Original poster
Apr 24, 2011
1
0
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:)
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
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

macrumors Pentium
Jan 28, 2009
15,046
4
Quebec, Canada
Did you try googling the obvious: palindrome python program

One of the top 10 hits is this:
https://forums.macrumors.com/threads/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

Moderator emeritus
Aug 16, 2005
19,366
979
New England
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.