[Tutor] Raw input query (?)

Lisi lisi.reisz at gmail.com
Thu Aug 25 11:46:33 CEST 2011


I copied and ran the following script:

multiplier = 12

for j in range(1,13):
    print "%d x %d = %d" %(j, multiplier, j*multiplier)

That ran perfectly and gave me the 12 times table.

I then decided that it would be fun to branch out and make teh 
script "universal", so I wrote and ran:

print "Which times table do you want?"

multiplier = raw_input ()

for j in range(1,13):
    print "%d x %d = %d" %(j, multiplier, j*multiplier)

The j in range section of code is identical, but I now get:

lisi at Tux:~/Python$ python multiplier.py
Which times table do you want?
4
Traceback (most recent call last):
  File "multiplier.py", line 8, in <module>
    print "%d x %d = %d" %(j, multiplier, j*multiplier)
TypeError: int argument required
lisi at Tux:~/Python$  

What extra should I have done because the variable value came from the 
keyboard, and why is it different from the first example?

Lisi




More information about the Tutor mailing list