You're not returning the values of answer and guess so it jumps out of the while loop and does the else. Try this:

def add(a,b):
    answer = a+b
    guess = float(raw_input(a," + ",b," = "))
    return answer, guess

answer, guess = add(num1,num2)
if guess != answer:

On 17/09/05, Nathan Pinno <[EMAIL PROTECTED]> wrote:
Hi all,
 
I've got this program I've written that should give an addition quiz, except it never enters the quiz. How do I make it enter the quiz?
 
Here is the code:
import random
 
def add(a,b):
    answer = a+b
    guess = float(raw_input(a," + ",b," = "))
 
num1 = random.choice(range(1,10))
num2 = random.choice(range(1,10))
 
while 1:
    q = random.choice(range(15,31))
    cq = 1
    correct = 0
    while cq >= q:
        add(num1,num2)
        if guess != answer:
            print "Incorrect! The correct answer is: ",answer
            cq += 1
        elif guess == answer:
            print "Correct!"
            correct += 1
            cq += 1
    else:
        print "Questions: ",q
        print "Correct: ",correct
        print "Percent Correct: ",(cq/q)*100
        break
 
print "Goodbye."
 
It just prints out for an example:
 
Questions:  17
Correct:  0
Percent Correct:  0
Goodbye.
 
Thanks,
Nathan Pinno

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor




_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to