[Tutor] How do fix this error?
Nathan Pinno
falcon3166 at hotmail.com
Sat Sep 17 06:51:44 CEST 2005
I changed the code and got an error:
Here is the screenshot containing the error:
27
Traceback (most recent call last):
File "D:\Python24\add_tutor.py", line 18, in -toplevel-
answer, guess = add(num1,num2)
File "D:\Python24\add_tutor.py", line 5, in add
guess = float(raw_input(a," + ",b," = "))
TypeError: [raw_]input expected at most 1 arguments, got 4
Here is the updated code:
import random
def add(a,b):
answer = a+b
guess = float(raw_input(a," + ",b," = "))
return answer, guess
num1 = random.choice(range(1,10)) ### To limit the numbers chosen from 1-9
num2 = random.choice(range(1,10))
q = random.choice(range(15,31)) ### to choose the number of questions
cq = 0 ### To find the current question
correct = 0
while 1:
cq = cq + 1
while cq >= q:
print cq
answer, guess = add(num1,num2)
if guess != answer:
print "Incorrect! The correct answer is: ",answer
elif guess == answer:
print "Correct!"
correct += 1
print "Questions: ",q
print "Correct: ",correct
print "Percent right: ",(correct/q)*100
print "Goodbye."
How do I fix it so that it runs without anymore errors or problems?
Thanks for the help so far,
Nathan Pinno
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050916/050017ca/attachment.htm
More information about the Tutor
mailing list