我写了下面的代码,但是当我试图运行它时,我得到了一个文件“C:\Users\Moses\Desktop”\测试.py“,第4行 def存款(自身): ^ IndentationError:应为缩进块错误。我需要帮助。在
class BankAccount(object):
def withdraw(self):
pass
def deposit(self):
pass
类节省帐户(银行帐户):
^{pr2}$类别当前金额(银行帐户): definit(自身,平衡=0.0): 自我平衡=平衡
def deposit(self,deposit_amount)
self.balance += deposit_amount
return self.balance
if amount < 0:
raise RuntimeError('Invalid deposit amount.')
return self.balance
def withdraw(self, withdraw_amount):
self.balance -= withdraw_amount
return self.balance
if withdwa_amount < 0:
raise RuntimeError('Invalid withdraw amount')
return self.balance
if withdwa_amount > self.balance:
raise RuntimeError('Cannot withdraw beyond the current account balance')
return self.balance
我需要一些关于缩进误差的帮助,知道它是什么以及如何解决它。我是python新手
需要进行许多更改。在
如果不想定义方法,可以使用
pass
def提取(自行): 通过
{cd2>之后应该有一个冒号
如果自我平衡<;500:
您的问题在于下面的函数定义;您不能只声明空函数,而需要为它们提供某种主体。在
另外,如果您直接复制粘贴了代码,那么看起来您没有使用足够的空格来缩进
例如,如果我复制粘贴线
def deposit(self):
它前面只有两个空格
这是正确的缩进和逻辑正确的代码。在获得社区支持之前,您必须阅读python编码指南。在
相关问题 更多 >
编程相关推荐