-2

This is the ending of a GUI quiz. You can choose what quiz you want to do out of a few topics.

Once you have completed a quiz, it tells you the score from that quiz and then you can go back to the main menu and choose a new subject.

The problem is the score adds on to the last one and doesn't reset back to 0.

I have marked the problem line with **.

def EndGame():
    global grade

    if score == 5:
        grade = "A"
    elif score == 4:
        grade = "B"
    elif score == 3:
        grade = "C"
    elif score == 2:
        grade = "D"
    elif score == 1:
        grade = "E"
    elif score == 0:
        grade = "F"

    def ReturnToMenu():
        root12.destroy()
        **score = 0** 
        Start()
0

1 Answer 1

0

ReturnToMenu is never actually called (at least in the code you gave us) with ReturnToMenu(). Also score only exists inside the function ReturnToMenu. You'd need to do

def ReturnToMenu():
    global score
    root12.destroy()
    score = 0
    Start()

but that is bad. You shouldn't be using global or nonlocal unless you really have to (hint: you don't). You need to completely rethink your design and try and do it without using either of these. You also have far too much code repetition. Try

grade = {5: 'A', 4: 'B', 3: 'C', 2: 'D', 1: 'E', 0: 'F'}[score]

instead of that verbose if / elif block.

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.