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 stores owner and balance
  • add(amount) that adds money to the balance
  • pay(amount) that takes money out, but raises ValueError("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) and w.add(5), w.balance is 25

Hints, the later steps and the answer come with Pro.

class Wallet:
    def __init__(self, owner, balance=0):
        ...