I have created a for
loop which is supposed to show me a question and, if replying correctly, it gives me 1 point. When I run the code, I see the questions correctly but when giving the correct answer to all questions, the result is only 1.
In the code below I have pasted the class used to define the object used in the loop and the loop which doesn't give me the total score.
It seems that the first and second questions if answered correctly, do not provide points, while the last question where the answer is "o", gives point
Classe.py
class Dom_matematica:
def __init__(self, operazione, risultato):
self.operazione = operazione
self.risultato = risultato
Survey
from Classe import Dom_matematica
Calcoli = [
"Quest1\n",
"Quest2\n",
"Quest3\n",
]
Ogg_Calcoli = [
Dom_matematica(Calcoli[0], 4),
Dom_matematica(Calcoli[1], 9),
Dom_matematica(Calcoli[2], "o"),
]
#HERE IS WHERE THE PROBLEM ARISES.
def Loop_mat(Ogg_Calcoli):
score = 0
for d in Ogg_Calcoli:
risposta = input(d.operazione)
if risposta == d.risultato:
score += 1
print("You got " + str(score) + "/" + str(len(Ogg_Calcoli)) + "
correct")
Loop_mat(Ogg_Calcoli)
I expect that the result gives 3/3 when all answers are correct