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))
_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to