我正在做一些处理Python中的类的作业。但是我陷入了一个我不太明白的部分。python中的类的提取方法
它告诉我:
- >写了一个名为withdraw()
方法提取从帐户中指定的指定金额。账户余额减少了方法参数中指定的金额。平衡只能降低如果参数小于规定的数额或等于平衡
这是我的计划
class Account:
def __init__(self,id=0):
self.__id = id
self.__balance = 0
self.__annualInterestRate = 0
def getid(self):
return self.__id
def getbalance(self):
return self.__balance
def getannualInterestRate(self):
return self.__getannualInterestRate
def setid(self):
self.__id = id
def setbalance(self):
self.__balance = balance
def getMonthlyInterestRate(self):
return self.__annualInterestRate/12
def getMonthlyInterest(self):
return self.__balance * getMonthlyInterestRate()
那么我将不得不:
def withdraw():
# I don't know what to do here
'getMonthlyInterestRate'和'getMonthlyInterest'缺少'self'参数 – 2013-04-04 09:17:33
对于''getMonthlyInterestRate'and它getMonthlyInterest'说写命名getMonthlyInterest AA方法()返还每月的利息金额。每月利息金额可以使用余额*月利率计算。每月利率可以通过年利率除以12来计算。 – Jett 2013-04-04 09:22:24
使用'self .__ balance * self.getMonthlyInterestRate()'而不是'self .__ balance * getMonthlyInterestRate()'。 – glglgl 2013-04-04 09:58:01