On Apr 23, 2007, at 1:57 AM, proctor wrote: > On Apr 22, 5:51 pm, Michael Bentley <[EMAIL PROTECTED]> wrote: >> Oops! Note to self: *ALWAYS* try code before posting to a public >> forum :-( >> >> def binary(val, width): >> print '%10s = the sum of' % val >> for i in [2 ** x for x in range(width - 1, -1, -1)]: >> a = val / i >> print ' ' * 13 + '%s * (2 ** %s)' % (a, width) >> val -= i * a >> width -= 1 >> >> binary(233, 8) > > hi michael, > > just a quick clarification... > > it seems to me that the self-documenting part of the code should be > more like this: > > print ' ' * 13 + '%s * (2 ** %s)' % (a, width-1) > > instead of > > print ' ' * 13 + '%s * (2 ** %s)' % (a, width) > > is this correct, or am i mixed? >
No, you're right -- actually I ended up decrementing width after the print instead of before it -- but didn't feel like posting yet another correction. Your correction works though! -- http://mail.python.org/mailman/listinfo/python-list