《python语言程序设计》2018版第7章第03题Account类设计一个Account类

设计一个Account类

题面

大家好,昨天停更了一次,因为买的二手苹果pro电脑,有很多问题没有 明白,在二手商家的指导下,完成重装系统,再装双系统。等等操作。再去健身房,基本上人已累倒。

请添加图片描述

新的改变

使用了新的mac电脑,今天上午教瑜伽,再去取鸡蛋,5个小时。回来重新整理思路,弄出的这段代码。

这是类的部分。


class Account:
    def __init__(self,id_name=0,balance=100,annual_interest_rate=0.00):
        self.id_name = id_name
        self.balance= balance
        self.annual_interest_rate = annual_interest_rate/100

    def set_id_name(self,id_name):
        self.id_name = id_name

    def get_id_name(self):
        return self.id_name

    def set_balance(self, balance):
        self.balance = balance

    def get_balance(self):
        return self.balance

    def set_annual_interest_rate(self,annual_interest_rate):
        self.annual_interest_rate = annual_interest_rate


    def get_monthly_interest_rate(self):
        return self.annual_interest_rate / 12


    def get_withdraw(self,with_money):
        return self.balance - with_money

    def get_deposit(self,deposit_mon):
        return self.balance + deposit_mon

    def get_monthly_interest(self):
        a = self.balance * self.get_monthly_interest_rate()
        return round(a,5)

这里是main的部分


def main():
    withdraw = eval(input("Enter withdraw money: "))
    deposit = eval(input("Enter deposit money: "))

    base_date= exCode07.Account(1122,20000,4.5)
    get_deposit_money =base_date.get_deposit(deposit)
    get_with_money= base_date.get_withdraw(withdraw)
    print(f"withdraw is balance {get_with_money}")
    print(f"deposit is balance {get_deposit_money}")
    print(f" account id is {base_date.id_name}")
    print(f"monthly interest {base_date.get_monthly_interest()}")
    print(base_date.annual_interest_rate)
    print(base_date.get_monthly_interest_rate())
main()

请添加图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

电饭叔

谢谢各位兄弟们的关注,谢谢破费

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值