observer pattern def unregister(selfobserver)self observers discard(observerdef unregister_all(self)self observers set(def update_all(self)for observer in self observersobserver update(selfclass user(object)def __init__(selfwallet)self wallet wallet self badges [self experience def add_experience(selfamount)self experience +amount def update(selfobserved)self add_experience( def __str__(self)return "wallet\ {}\nexperience\ {}\nbadges +\ {}\ ++++++++++++++++formatself walletself experience"\njoin(str(xfor in self badges]class wallet(object)def __init__(self)self amount def increase_balance(selfamount)self amount +amount