Context Managers

Medium Design Patterns & Final Challenges
Solve in Playground →

Problem Statement

Create a `Timer` class implementing the context manager protocol via `__enter__` and `__exit__`. In `__enter__`, print ‘Timer Started’. In `__exit__`, print ‘Timer Stopped’. Use it with a `with` statement wrapper to execute a mock payload block printing ‘Working…’.

Input Format

None

Output Format

Print the sequence of events during context setup, payload, and teardown.

Constraints

None

Sample Output

Timer Started
Working...
Timer Stopped

Explanation

Context managers guarantee structural setup and teardown tasks (like closing files or handling locks) even if exceptions occur inside the block.

Starter Code

class Timer:
    # Implement __enter__ and __exit__
    pass

if __name__ == '__main__':
    # Use with statement
    pass

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used