Catching and Handling Object-Specific Errors

Medium Exception Handling in OOP
Solve in Playground →

Problem Statement

Create a `Calculator` class with a method `divide(a, b)`. In the main block, read two integers, call the method inside a try-except block, catch Python’s built-in `ZeroDivisionError`, and print ‘Cannot divide by zero’.

Input Format

Two space-separated integers.

Output Format

Print the integer result (using int() cast) or the error message.

Constraints

None

Sample Input

10 0

Sample Output

Cannot divide by zero

Explanation

When an object's method performs an unsafe operation, the caller should wrap the invocation in a targeted except block.

Starter Code

class Calculator:
    # Define divide method
    pass

if __name__ == '__main__':
    a, b = map(int, input().split())
    # Instantiate and safely call divide
    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