A simple wallet class
Easyclass__init__methodsraise· 10 XP
A payments app needs a small Wallet object that keeps a balance and blocks payments the user can't afford.
Write a class Wallet with:
Wallet(owner, balance=0)that storesownerandbalanceadd(amount)that adds money to the balancepay(amount)that takes money out, but raisesValueError("not enough money")if the amount is more than the balance (and leaves the balance unchanged)
How it's checked
Your code runs, then the check below runs and its printed output is compared with ours.
- After
w = Wallet("Ana", 20)andw.add(5),w.balanceis25
Hints, the later questions and the answer come with Pro.
class Wallet:
def __init__(self, owner, balance=0):
...