【发布时间】:2021-02-09 07:41:33
【问题描述】:
B)BankAccount 类应该有两个子类,名为 SavingsAccount 和 NonTaxFilerAccount。 SavingsAccount 类应该有一个 ZakatDeduction( ) 函数,该函数在调用时会扣除当前账户余额的 2.5%。 NonTaxFilerAccount 类应该覆盖父类的withdraw 函数。每次提款时都会从账户中扣除 2% 的预扣税。
我做了第一部分,但没有得到第二部分,它一直给我属性错误
class BankAccount:
def __init__(self, init_bal):
"""Creates an account with the given balance."""
self.init_bal = init_bal
self.account = init_bal
def deposit(self, amount):
"""Deposits the amount into the account."""
self.amount = amount
self.account += amount
def withdraw(self, amount):
self.account -= amount
def balance(self):
print (self.account)
class SavingsAccount(BankAccount) :
def ZakatDeduction(self,amount):
self.account=amount*0.25
print(self.account)
class NonTaxFilerAccount(BankAccount):
def withdraw(self, amount):
self.account -= amount*(0.2)
print(self.account)
x = BankAccount(700)
x.balance()
y=BankAccount
y.SavingsAccount(700)
z=BankAccount
z.withdraw(70)
【问题讨论】:
标签: python-3.x oop