runtime
257 / 500
question 257 Classes & Objects · medium

From dictionary functions to a class

A shop's store-credit accounts are dictionaries handled by three loose functions. Refactor them into a class CreditAccount with the same behaviour: same limits, same counting of declined charges, same results. The starter's functions are correct; keep them as a reference while you write the class, then remove them.

ClassCreditAccount(owner, limit) with attributes owner, limit, spent (starts 0) and declined (starts 0)
`charge(amount)`like charge(account, amount): returns True and adds to spent, or returns False and adds 1 to declined when the charge would take spent above limit
`remaining()`like remaining(account): limit - spent

Loading your progress…

From dictionary functions to a class — Python practice · Runtime