[Tutor] Why won't it enter the quiz?

Nathan Pinno falcon3166 at hotmail.com
Sat Sep 17 03:18:36 CEST 2005

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:
        if guess != answer:
            print "Incorrect! The correct answer is: ",answer
            cq += 1
        elif guess == answer:
            print "Correct!"
            correct += 1
            cq += 1
        print "Questions: ",q
        print "Correct: ",correct
        print "Percent Correct: ",(cq/q)*100

print "Goodbye."

It just prints out for an example:

Questions:  17
Correct:  0
Percent Correct:  0

Nathan Pinno
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050916/6fb9ba65/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Pinno, Nathan Paul.vcf
Type: text/x-vcard
Size: 783 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20050916/6fb9ba65/PinnoNathanPaul.vcf

More information about the Tutor mailing list