Python 0-to-Hero Mastery (Big Tech SDE & ML Standard) › 05. Variables, Scope & The LEGB Rule (Local, Enclosing, Global, Built-in)
45 mins
← Prev Next →
Course Syllabus
Interactive Lesson Studio
Loading lesson content...

🎯 Big Tech Coding & Interview Challenges

Practice these curated problems. Click "Load in Sandbox" to solve live in the Code Studio!

1 Questions
Easy

1. State Tracking Closure with Nonlocal

Ek closure function `make_accumulator(initial=0)` likhein jo `nonlocal` ka use karke internal total track kare aur har call par added value accumulate kare.

acc = make_accumulator(10); acc(5) -> 15; acc(20) -> 35
💡 View Pro Interview Hint
• Use `nonlocal total` inside the inner function.
Python 3.12
Live Execution Terminal
Click "Execute Live" to run code.