LearnPy Hub
← Classes & Objects problems
Hard

Account With Undo

Write class Account with deposit(x), withdraw(x) (refused with insufficient if too large, and not recorded) and undo() that reverses the last successful deposit or withdrawal (nothing to undo if there is none). Keep the history in a list. Read commands until END and print the balance after each successful command, or the message.

Input

Commands deposit X, withdraw X, undo, then END.

Output

Lines.

Sample 1

Input
deposit 100
withdraw 30
undo
undo
undo
END
Output
100
70
100
0
nothing to undo

Sample 2

Input
withdraw 5
END
Output
insufficient
solution.py
Output appears here
Account With Undo · Python practice problem · LearnPy Hub