Re: Checking a Number for Palindromic Behavior



On Oct 18, 9:45 pm, alex23 <wuwe...@xxxxxxxxx> wrote:
On Oct 19, 12:32 pm, ru...@xxxxxxxxx wrote:
On Oct 18, 4:20 pm, MRAB <pyt...@xxxxxxxxxxxxxxxxxxx> wrote:
Benjamin Middaugh wrote:
Thanks to everyone who helped with my query on reversing integers. I
have one more simple problem I'm having trouble solving. I want to check
a number for palindromic behavior (reading the same backwards and
forwards). So if I have an integer 1457 it can tell me this is not the
same from both ends but 1551 is. I think the simplest way would be to
work inwards from both ends checking digits for equality, but I don't
know enough (yet) to do this.

All help is much appreciated.

It's a palindrome if it's the same as its reverse. You already know how
to reverse it, and you should already know how to check whether two
things are the same, so... :-)

Something like:

def is_palidrome (n):
    return str(n) == ''.join (reversed (str(n)))

which will return True if integer n is a palidromic or False
otherwise.

_Not_ providing the code was MRAB's entire point here. It's nice to
show that you're clever and all, but that doesn't really help the OP
learn.

I hardly think that code is evidence of cleverness.

Re helping the OP learn...

MRAB (and gherron) were wrong.

One, it was suggested without any evidence the the OP was
"probably" asking about homework. My observation over
several years is that this group has a very poor record
of identifying homework problems. And if someone can
conclude that the OPs problem was homework with no evidence,
then I can conclude that it wasn't, without evidence,
equally validly.

As for learning better by "working it out oneself", that is
a myth. I know it is not (universally) true by counter-example:
I once asked a question here got several answers. One
person explained the behavior I'd not understood in a single
sentence. Another provided a long transcript of an interactive
Python session intended to demonstrate the behavior and its
origin. I read the first response and it was immediately
clear what my misunderstanding was, and why Python was doing
what I hadn't understood. I never bothered with the long
demo since it would have been a waste of my time, despite
that the poster had obviously put significant time into
writing it.

I realize that in many courses the pedagogy involves working
out the basic ideas, theorems, etc. But the environment
of a course taught by an instructor thoughorly covering an
organized range of topics is totally different than a usenet
newsgroup.

Different people have different goals and learning styles.
I gave the OP another option. He can choose whichever
helps him learn most effectively. That is a *good* thing.


.



Relevant Pages

  • Re: Norton Resistance Question
    ... hostility. ... After that I calculate resistance using Ohm's Law. ... That which is claimed without evidence can be dismissed without ... If you think it is homework, then email me on January 1st with your ...
    (sci.electronics.basics)
  • Re: Norton Resistance Question
    ... hostility. ... complete question without alterior motives and hidden ... That which is claimed without evidence can be dismissed without ... If you think it is homework, then email me on January 1st with your ...
    (sci.electronics.basics)
  • Re: making fun of atheists
    ... evidence for what you're saying. ... to name the first "real" pope? ... when will you admit that you were utterly flabbergasted by the ... obviously i've done my homework adequately enough for that. ...
    (misc.writing)
  • Re: Cracking the Mayan Code on Nova PBS
    ... have found no evidence of such machinery, ... Actually they have but par for the course you have not done your ... homework. ...
    (rec.music.classical.guitar)