Skip to main content

Practice ยท 3 of 3

Reusable context manager

Implement class Timer usable as a context manager AND reusable across runs: - with Timer() as t: โ€” on exit, t.elapsed is a float โ‰ฅ 0 seconds - t.runs counts completed blocks - nested usage of two Timers must be independent - entering must return the timer itself

Difficulty: advanced

Back to lesson: Practice: Custom Container Practice