Login and get codingLet's enrich an Account class by adding dunder (aka special) methods to support the following:
- length of the object:
len(acc)
returns the number of transactions- account comparison:
acc1 >,<,>=.<=,== acc2
returns a boolean comparing account balances- indexing:
acc[n]
shows the nth transaction onaccount
(0 based)- iteration:
list(acc)
returns a sequence of account transactions- operator overloading:
acc + int
andacc - int
can be used to add/subtract money (if given incompatible types for these operations, raise aTypeError
- note that previously this was aValueError
, but former is more correct for this scenario)- string representation:
str(acc)
returns NAME account - balance: INTThe provided template already does some setup for you.
Check out the tests for more specifics. If you're still new to dunder (magic) methods, here is an article you might find useful. Good luck!
375 out of 398 users completed this Bite.
Will you be the 376th person to crack this Bite?
Resolution time: ~48 min. (avg. submissions of 5-240 min.)
Our community rates this Bite 4.12 on a 1-10 difficulty scale.
» Up for a challenge? 💪