avatar Bite 20. Write a context manager

Write a context manager to roll back a transaction on the given Account class.

There are two special (aka dunder) methods you need to define to create a context manager (there is also a convenient decorator - see Bite 88).

The purpose of the context manager is to roll back any transaction that will make the balance go below 0 (debt != cool). The rest of the class is already defined so you can focus on the context manager part.

See the tests for more detail. Good luck and keep calm and code in Python!

Login and get coding
go back Advanced level
Bitecoin 4X

380 out of 382 users completed this Bite.
Will you be Pythonista #381 to crack this Bite?
Resolution time: ~38 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 5.21 on a 1-10 difficulty scale.
» Up for a challenge? 💪

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help