class - 一个python作业题,关于类的书写
大家讲道理
大家讲道理 2017-04-17 15:05:01
0
1
351
class BankAccount: """ Class definition modeling the behavior of a simple bank account """ def __init__(self, initial_balance): """Creates an account with the given balance.""" … def deposit(self, amount): """Deposits the amount into the account.""" … def withdraw(self, amount): """ Withdraws the amount from the account. Each withdrawal resulting in a negative balance also deducts a penalty fee of 5 dollars from the balance. """ … def get_balance(self): """Returns the current balance in the account.""" … def get_fees(self): """Returns the total fees ever deducted from the account.""" …

The deposit and withdraw methods each change the account balance. The withdraw method also deducts a fee of 5 dollars from the balance if the withdrawal (before any fees) results in a negative balance. Since we also have the method get_fees, you will need to have a variable to keep track of the fees paid.

Here's one possible test of the class. It should print the values 10 and 5, respectively, since the withdrawal incurs a fee of 5 dollars.

my_account = BankAccount(10) my_account.withdraw(15) my_account.deposit(20) print my_account.get_balance(), my_account.get_fees()
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

모든 응답 (1)
巴扎黑

python小白,求大神来解答呀!!!!!!!!!!!!!!!!万分感谢

    최신 다운로드
    더>
    웹 효과
    웹사이트 소스 코드
    웹사이트 자료
    프론트엔드 템플릿
    회사 소개 부인 성명 Sitemap
    PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!