[Tutor] blank space after a number
Noah Hall
enalicho at gmail.com
Wed Dec 29 01:09:43 CET 2010
I'll just add there's a better way to do both of the examples you've done
there -
> > a, b = 0, 1
> > while b < 10:
> > print '%i%i' % (a,b) + ',',
> > b = b+1
An easier way of doing this is to instead do the following, including the a
(although not needed, as simply using 0 would work) -
a, b = 0, 1
while b <10:
print '%i%i,' % (a,b),
b += 1
> while b < 100:
> > print '%i' % (b) + ',',
> > b = b+1
>
while b < 100:
print '%i,' % (b),
b += 1
Or, using generators and a *for *loop (which is more suited to the task than
a *while *loop):
def stringify(x):
if x < 10:
return '0' + str(x)
else:
return str(x)
print ','.join(stringify(x) for x in xrange(1,101))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101229/0e8bd22f/attachment.html>
More information about the Tutor
mailing list