State Rollback on Error

Medium Exception Handling in OOP PRO
🔒 Login to Unlock

Problem Statement

Create an `Account` class. The `process(amount)` method deducts the amount from `balance`. If `balance` drops below 0, it must revert the `balance` to its previous state and raise a `ValueError(‘Insufficient Funds’)`. Print either ‘Success: [balance]’ or ‘[error]: [balance]’.

Input Format

Two integers: starting balance and deduction amount.

Output Format

Print the result and the final protected balance.

Constraints

None

Sample Input

100 150

Sample Output

Insufficient Funds: 100

Explanation

A critical OOP pattern: if a method fails halfway, it must clean up and restore the object's state before raising the error.

Starter Code

class Account:
    def __init__(self, balance):
        self.balance = balance
    # Define process with rollback logic

if __name__ == '__main__':
    b, amt = map(int, input().split())
    # Execute and handle exception
    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