Skip to main content

Practice · 3 of 3

Reusable context manager

CHALLENGE
Difficulty: advanced+25 XP

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

Back to lesson: Practice: Custom Container Practice