Late-Binding Closures

Talk it through with a coach who asks guiding questions and gives hints until you reach the answer. Pass to mark the challenge as completed.

The problem

  • hard
  • Pro

A loop creates five small functions, each meant to return its own loop number, but calling them all returns four. Explain why Python closures behave like this and how to fix it.

Talk this problem through with an AI coach

This is a Pro challenge. Sign in with Google, then upgrade to start a voice session.

Start free →