Skip to content Skip to sidebar Skip to footer

Python Arithmetic Quiz Task 1

I have no idea why this code is not working, as you can see I'm trying to ask the user 10 questions display their score at the end. Everything works except that the score will alwa

Solution 1:

Each call to question() resets score to be 0. Remove the score=0 line from that function, and instead initialize it in main:

def main():
    global score;
    score = 0;
    for i inrange (10):
        question()
        checking()
    print("your score is", score)

Solution 2:

You can error check to see if your variable to count has been initialized. It's not the cleanest solution but does the job.

def checking():
try:
    global scorescore= score
except:
    global scorescore=0ifoperation== "*":
    trueanswer = number1*number2
    ifstudentanswer== trueanswer:
        print("correct")
        score=score+1

Post a Comment for "Python Arithmetic Quiz Task 1"