Recursion

William Park opengeometry at NOSPAM.yahoo.ca
Fri Jul 19 18:57:03 EDT 2002


>>    def showbits(x):
>>        if x != 1:
>>          showbits(x >> 1)        
>>        if x & 01:
>>            print 1,
>>        else:
>>            print 0,

Final answer:

    def showbits(x):
	if x <= 1:
	    return `x`
	else:
	    return f(x>>1) + `x&1`

-- 
William Park, Open Geometry Consulting, <opengeometry at yahoo.ca>
8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin



More information about the Python-list mailing list