On Sun, 18 Oct 2009 19:34:09 +0100, Benjamin Middaugh <benjamin.the.violin...@gmail.com> wrote:

I'm trying to make an integer that is the reverse of an existing integer such that 169 becomes 961. I guess I don't know enough yet to figure out how to do this without a ton of awkward-looking code. I've tried for loops without much success. I guess I need a good way of figuring out the length of the input integer so my loop can iterate that many times to reverse the number, but I keep getting errors that say "TypeError: 'Int' object is not iterable".

Alternatively, turn your integer into a string, reverse the string, and
turn it back:

rho...@gnudebst:~$ python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:58:18)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
n = 123
int(str(n)[::-1])
321



--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to