runtime
272 / 500
question 272 Data Models & Typing · easy

Money that misbehaves

Money should print as £12.50 and compare equal only when both the amount and the currency match. Printing crashes with TypeError: __str__ returned non-string, and £10 compares equal to €10. Fix the two special methods.

`str(Money(1250, "GBP"))`£12.50 (symbols: GBP £, USD $, EUR €)
`==`True only for the same cents and currency; NotImplemented for anything that isn't Money

Loading your progress…

Money that misbehaves — Python practice · Runtime