[Tutor] modification

Rob Andrews rob@jam.rr.com
Mon, 20 Aug 2001 11:25:42 -0500


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
> 
> -Dutch

I noticed a few things:

# use input instead of raw_input
num = input('What shall I count to? ')
counter=0
while counter <= num:
	print 'loop #%d' % (counter)
	counter = counter + 1
# check your % syntax. Notice the differences in the way you used
# commas and parentheses on lines 4 and 6 of your script?
print 'your number was: %d' % (num)

Rob
-- 
A {} is a terrible thing to waste.
Useless Python!
http://www.lowerstandard.com/python