Help printing the integers of a longer number

Chris Angelico rosuav at
Thu Mar 28 18:17:19 CET 2013

On Fri, Mar 29, 2013 at 4:03 AM, Jussi Piitulainen
<jpiitula at> wrote:
> def print_digits(num):
>    left, last = divmod(num, 10)
>    if left < 0: print the digits of left
>    print(last)
> How do you print the digits of left? With print_digits. Why does it
> work? Because you only call print_digits again when left is closer to
> zero than num.
> It's called recursion.

An elegant solution, but buggy, I'm afraid... fortunately it's a
trivial problem. The comparison should be left>0. :)


More information about the Python-list mailing list