第十四章 对象-注意实际运用

注意实际运用-银行存钱取钱练习

class BankAccount:
    def __init__(self,name,accountNumber,balance):
        self.name = name
        self.accountNumber = accountNumber

        self.balance = balance

 

    def save(self,saveMoney):
        self.balance = self.balance + saveMoney
        return self.balance
   
    def draw(self,drawMoney):
        if drawMoney > self.balance:
            print "Your balance is not enough."
        else:
            self.balance = self.balance - drawMoney
            return self.balance
        
    def __str__(self):
        msg = "Hello"+"\n"+"You account name is " + self.name+"."+"\n"+"You account number is "\
              + self.accountNumber+"."+"\n" + "You account balance is "+ str(self.balance)+"$"+"."
        return msg
myBankAccount = BankAccount("sunpu","4213 4942 2364 4154 ",1000.00)


print myBankAccount


myBankAccount.save(1500)
print myBankAccount


myBankAccount.draw(3500)
print myBankAccount


myBankAccount.draw(2000)

print myBankAccount

第十四章 对象-注意实际运用