[Tutor] Problem with while loop

Michael Connors connorsml at gmail.com
Fri Sep 7 13:54:18 CEST 2007


I think it will work if you cast your input to an int:
howmany = int(raw_input( "How many: " ))

On 07/09/2007, matte <mailinglistmatt at gmail.com> wrote:
>
> Hi guys
>
> Please excuse me but I've been out of Python for a while since my laptop
> was stolen...
>
> I'm battling with a very basic while loop....
>
> -------------- 8< ----------------------
> #!/usr/bin/python
>
> from random import randint
>
> counter = 0
>
> howmany = raw_input( "How many: " )
>
> while counter < howmany:
>
>     pin = randint(0000,9999)
>     print pin
>     counter += 1
>
> -------------- 8< ----------------------
>
> For some reason if I use an integer in place of "howmany" it works, but
> I'd
> like it to work as I can logically see it above.
>
> What am I missing ?
>
> -m
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Michael Connors
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070907/c8980748/attachment.htm 


More information about the Tutor mailing list