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
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to