Return a Value

Add return is_correct so the caller can update the score based on the result

💻

Writing code and entering commands is only available on desktop. Open this page on a larger screen to complete this chapter.

ask_question displays a question and prints feedback, but the for loop still needs to know whether the player was correct — to update score and streak. Right now, the function prints the feedback but doesn't communicate the result back to the caller.

Return sends a value back

Use return at the end of the function to send a value back to whoever called it:

def ask_question(text, o1, o2, o3, o4, correct):
    # ... display, input, feedback ...
    return is_correct

The caller can then use the result:

result = ask_question(text, o1, o2, o3, o4, correct)
if result:
    score = score + 1

Without return, the function returns None

If a function has no return statement, Python returns None. None is falsy — if None: is always False. That means if result: would never run, and every answer would look wrong even when the player is correct.

What changes in the for loop

Once ask_question returns is_correct, the for loop body shrinks from 14 lines to 8. The display, input, and feedback move inside the function. Only the score and streak logic stays in the loop.

The starter code has already made this update to the for loop — your job is to add the return statement that makes it work.

Instructions

Add a return statement to ask_question.

  1. At the very end of the ask_question function body, after the else clause, add return is_correct — this sends the result back to the caller so the for loop can update score and streak based on whether the player was correct. Without return, the function returns None, and if result: would never be True.