[Tutor] (no subject)

Yigal Duppen yduppen@xs4all.nl
Fri, 9 Aug 2002 16:50:41 +0200


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> I am having a strange problem with my python code for reversing a
> number. 

There is an interesting bug in your program, based on a wrong assumption.
My suggestion: replace the while loop by the following code

while (number/10) > 1 :
    print "A) number/10:", number/10, "temp:", temp_var, "number:", number
    temp_var = (temp_var*10) + (number%10)
    number = number/10
else:
    print "B) number/10:", number/10, "temp:", temp_var, "number:", number
    temp_var = (temp_var*10) + number
    print 'The reversed number is ', temp_var 

(in other words: add some debug output)
and try to figure out what went wrong. You'll probably find it pretty soon :)

YDD
- -- 
http://www.xs4all.nl/~yduppen
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9U9bBLsKMuCf5EdwRAoZLAKCu7cdV+89eZiANZKLHCJ09ll/wMQCgyu+V
J64RHjTS+lc8ihjB8a7eNuI=
=QAar
-----END PGP SIGNATURE-----