定义一个类Account
class Account:
def __init__(self, num. nane,balance-0):
self.num=num
self.name=name
selt.balance =balance
print("账户创建成功.".self)
定义存钱方法
def put(self, money):
self.balance = self.balance + money
print("成功存入”,money,".".self)
pass
定义取钱方法
def get(self, money):
if self.balance < money:
print("余额不足,取款失败,请调整取款金额")
else:
self.balance = self.balance - money
print("成功取走",money,",",self)
pass
定义转账方法
def transform(self, other, money):
if self.balance <money:
print(“余额不足,转账失败,请调整转账金额:)
else:
self.balance - self.balance - money
other. balance-other.balance+money
print("账号{}向账号{}成功转了{}}".format (self.num, other.num, money) ) print(self)
print(other)
pass