LearnPy Hub
← Decorators problems
Hard

Count Calls per Method

Write a decorator counted for methods that adds 1 to self.calls[method_name] each time the method runs. Use it on deposit and withdraw of an Account class. Process deposit x / withdraw x lines until END, then print the balance and the calls dictionary sorted by name.

Input

Lines, then END.

Output

Lines.

Sample 1

Input
deposit 100
withdraw 30
deposit 5
END
Output
75
{'deposit': 2, 'withdraw': 1}

Sample 2

Input
withdraw 1
END
Output
-1
{'withdraw': 1}
solution.py
Output appears here
Count Calls per Method · Python practice problem · LearnPy Hub