同学,你好!参考代码如下:
class BankUser():
def __init__(self):
self.des="转入"
self.amount=5380
self.time="2020-03-01"
def wangzhuan(self,amount,time,des):
if des=="网转":
self.des="网转"
if des=="消费":
self.des = "消费"
self.amount=self.amount-amount
print("{}\t{}\t\t-{:0.2f}\t{}\t {:.2f}".format(time, des,amount,"人民币", self.amount))
def zhuanru(self,amount,time,des):
self.des="转入"
self.amount=self.amount+amount
print("{}\t{}\t\t{:+.2f}\t{}\t{:.2f}".format(time, des,amount,"人民币", self.amount))
user=BankUser()
print("交易日期\t\t摘要\t\t金额\t\t\t币种\t\t余额")
user.wangzhuan(5000.00,"2020-03-06","网转")
user.zhuanru(500,"2020-05-08","转入")
user.wangzhuan(100,"2020-08-10","消费")
user.wangzhuan(99,"2020-12-25","消费")
user.zhuanru(27800,"2021-01-05","转入")
祝学习愉快~
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星