[Tutor] modification

Koen Bossers koen@behindthesofa.dhs.org
Mon, 20 Aug 2001 17:57:39 +0200


Dutch wrote:

>going through 'Core python programming' and modified an example to see
>what would happen.  Well, errors happen. 
>
>I wanted it to ask me for a number then loop that many time and finally
>report to me what my number was.  This is what I typed that made the
>erros:
>
>num = raw_input ('What shall I count to? ')
>counter = 0
>while counter <= num:
>    print 'loop #%d' %(counter)
>    counter = counter + 1
>print 'Your number was: %d', %num
>
'num' in your example is a string, not an integer!
Use this instead:

while counter <= int(num):

and you're set!

Cheers, Koen