# 第23章示例:银行账户类(封装雏形)

class Account:
    """银行账户:能存钱、取钱、查余额"""

    def __init__(self, holder, balance=0):
        self.holder = holder      # 户主
        self.balance = balance    # 余额

    def deposit(self, amount):
        """存款"""
        if amount <= 0:
            print("金额必须大于 0!")
            return
        self.balance += amount
        print(f"{self.holder} 存入 {amount},余额 {self.balance}")

    def withdraw(self, amount):
        """取款(余额不足则拒绝)"""
        if amount > self.balance:
            print("余额不足!")
            return
        self.balance -= amount
        print(f"{self.holder} 取出 {amount},余额 {self.balance}")

    def show(self):
        print(f"{self.holder} 的余额:{self.balance}")


# 使用
acc = Account("小明", 100)
acc.deposit(50)      # 小明 存入 50,余额 150
acc.withdraw(200)    # 余额不足!
acc.withdraw(30)     # 小明 取出 30,余额 120
acc.show()           # 小明 的余额:120
