Recursion
Carsten Gaebler
clpy at snakefarm.org
Fri Jul 19 17:47:12 EDT 2002
Matthias Urlichs wrote:
> Abhijit Soman <abhijit_som at yahoo.co.in> wrote:
>
>> def showbits(x):
>> if x != 1:
>> showbits(x >> 1)
>> if x & 01:
>> print 1,
>> else:
>> print 0,
>
>
> It's interesting that nobody seems to have caught the infinite recursion
> when you try to show a value which happens to be zero...
>
... which, of course, we would elegantly resolve by saying:
try:
showbits(foo)
except RuntimeError:
print 0
;-)
cg.
More information about the Python-list
mailing list