# I want score from 0 to 100 but when I try to calculate score, it's always 0.33333333 or something. Plz help.

asked Apr 2, 2019 1 flag
edited Apr 2, 2019
I want a score from 0 to 100% but when I try to calculate the score, it is always 0.33333333333 or something like that. Why is this happening? And I also want a way to be able to get a 100% because when I get one it always says "q is not defined". Here is the code:

q=0
print("Welcome to this math test.")

pie=input("What is 5-3?")
if pie=='2':
print("Good")
q=+1
else:
print('Wrong')
toe=input("What is 9-6?")
if toe=='3':
print('Better')
q=+1
else:
print("Wrong")
fed=input('What is 12x11?')
if fed=='132':
print('Fantastical')
q=+1
else:
print("Wrong")
result=q/3
print(result,'%')

answered Apr 2, 2019 by (580 points)
selected Apr 3, 2019 by Paolo Nader

It is because you typed wrong statement when want to increment q by 1.
You typed: q=+1 three times, but it have to be q+=1 instead.
With your code, q could be 3 times assigned as +1, and later when you calculate result you get
result = 1/3 if one or all correct answers.
Also, if you want result to be like 33%, 66%.. you should multiply actual result with 100
answered Nov 7, 2019 by (1,090 points)
q=0
print("Welcome to this math test.")

pie=input("What is 5-3?")
if pie=='2':
print("Good")
q=1
else:
print('Wrong')
toe=input("What is 9-6?")
if toe=='3':
print('Better')
q=q+1
else:
print("Wrong")
fed=input('What is 12x11?')
if fed=='132':
print('Fantastical')
q=q+1
else:
print("Wrong")
result=q/3
print(result,'%')

output

Welcome to this math test.