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

0 votes
asked Apr 2 by (260 points)
edited Apr 2 by
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.")
print('Here is your first question.')

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")
print("Here is your score")
result=q/3
print(result,'%')

2 Answers

0 votes
answered Apr 2 by (540 points)
selected Apr 3 by
 
Best answer
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
0 votes
answered Nov 7 by (1,070 points)
q=0
print("Welcome to this math test.")
print('Here is your first question.')

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")
print("Here is your score")
result=q/3
print(result,'%')

output

Welcome to this math test.
Here is your first question.
What is 5-3?2
Good
What is 9-6?3
Better
What is 12x11?132
Fantastical
Here is your score
1.0 %
 

here u go

i is working
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...