# Why doesn't the following program enter the quiz?

Why doesn't the following code enter the quiz?

import random

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:
cq += 1
print "Correct!"
correct += 1
cq += 1
else:
print "Questions: ",q
print "Correct: ",correct
print "Percent Correct: ",(cq/q)*100
break

print "Goodbye."

Here is a sample output when I run it:
Questions: 27
Correct: 0
Percent Right: 0
Goodbye!

How do I make it enter the quiz?
Swat spam before it fills your inbox!

• : Why doesn't the following code enter the quiz?
:
: import random
:
: guess = float(raw_input([red]a," + ",b," = "[/red]))
:
: num1 = random.choice(range(1,10))
: num2 = random.choice(range(1,10))
:
: [red]while 1:[/red]
: q = random.choice(range(15,31))
: cq = [red]1[/red]
: correct = 0
: while cq >= q:
: cq += 1 [red]#either way it gets executed[/red]
: elif guess == answer: [red]#at this point it can only be equal[/red]
: print "Correct!"
: correct += 1
: cq += 1
: else:
: print "Questions: ",q
: print "Correct: ",correct
: print "Percent Correct: ",[red](cq/q)[/red]*100 [red]#correct/cq and it needs a typecast to get a float result[/red]
: break [red]#not needed[/red]
:
: print "Goodbye."
:
: Here is a sample output when I run it:
: Questions: 27
: Correct: 0
: Percent Right: 0
: Goodbye!
:
: How do I make it enter the quiz?
: Swat spam before it fills your inbox!
:

I highlighted the mistakes...
Hope that I got what you would've liked to accomplish with it.
Something like this:
[code]
import random

guess = float(raw_input("%d + %d = " % (a, b)))

q = random.choice(range(3,8))
cq = 0
correct = 0
while cq <= q:
num1 = random.choice(range(1,10))
num2 = random.choice(range(1,10))
else:
print "Correct!"
correct += 1
cq += 1
else:
print "Questions: ",cq
print "Correct: ",correct
print "Percent Correct: %3.2f" %((float(correct)/cq)*100)

print "Goodbye."
[/code]

Drost
• : : Why doesn't the following code enter the quiz?
: :
: : import random
: :
: : guess = float(raw_input([red]a," + ",b," = "[/red]))
: :
: : num1 = random.choice(range(1,10))
: : num2 = random.choice(range(1,10))
: :
: : [red]while 1:[/red]
: : q = random.choice(range(15,31))
: : cq = [red]1[/red]
: : correct = 0
: : while cq >= q:
: : if guess != answer:
: : cq += 1 [red]#either way it gets executed[/red]
: : elif guess == answer: [red]#at this point it can only be equal[/red]
: : print "Correct!"
: : correct += 1
: : cq += 1
: : else:
: : print "Questions: ",q
: : print "Correct: ",correct
: : print "Percent Correct: ",[red](cq/q)[/red]*100 [red]#correct/cq and it needs a typecast to get a float result[/red]
: : break [red]#not needed[/red]
: :
: : print "Goodbye."
: :
: : Here is a sample output when I run it:
: : Questions: 27
: : Correct: 0
: : Percent Right: 0
: : Goodbye!
: :
: : How do I make it enter the quiz?
: : Swat spam before it fills your inbox!
: :
:
: I highlighted the mistakes...
: Hope that I got what you would've liked to accomplish with it.
: Something like this:
: [code]
: import random
:
: guess = float(raw_input("%d + %d = " % (a, b)))
:
: q = random.choice(range(15,31))
: cq = 0
: correct = 0
: while cq <= q:
: num1 = random.choice(range(1,10))
: num2 = random.choice(range(1,10))
: else:
: print "Correct!"
: correct += 1
: cq += 1
: else:
: print "Questions: ",cq
: print "Correct: ",correct
: print "Percent Correct: %3.2f" %((float(correct)/cq)*100)
:
: print "Goodbye."
: [/code]
:
: Drost
:
Thanks, now it works perfectly! Now I know how to fix my big program as well!
Swat spam before it fills your inbox!