[Tutor] How to make the loop work?

doug shawhan doug.shawhan at gmail.com
Thu Jun 22 17:06:04 CEST 2006


Hi Bob,

You can use a while loop in this case, but range() might be a bit more
appropriate!

c = 0
d = raw_input("Enter Number Limit: ")

for i in range(int(d)): #note, we make sure "d" is an integer!
    c = c + 1
    print c

On 6/22/06, Bob Gailer <bgailer at alum.rpi.edu> wrote:
>
> Ivan Low wrote:
> > Hi, I'm new to python trying to figure how to make this work.
> >
> > c=0;d=raw_input("input number limit: ")
> >
> > while 1:
> >     c = c + 1
> >     if c == d: break
> >     print c,
> >
> >
> > My idea is to able to input a number to limit the print out of this
> loop.
> > But this will not work. Where is the error?
> >
> "Will not work" does not (in general) give us enough to go on. Please in
> the future tell us what the evidence of the problem is - e.g. unexpected
> output, exception, ... If it is an exception please include the
> traceback in your post.
>
> --
> Bob Gailer
> 510-978-4454
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060622/22bc394f/attachment.html 


More information about the Tutor mailing list