Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

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, 2019 by Paolo Nader (290 points) 1 flag
edited Apr 2, 2019 by Paolo Nader
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

+2 votes
answered Apr 2, 2019 by bolarisme (580 points)
selected Apr 3, 2019 by Paolo Nader
 
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, 2019 by dheeraj (1,090 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.
...