我写了下面的代码,但是当我尝试运行它时,我得到一个文件“C:\ Users \ Moses \ Desktop \ test.py”,第4行 def deposit(self): ^ IndentationError:预计会出现缩进块错误。我需要帮助。Python解决缩进错误
class BankAccount(object):
def withdraw(self):
pass
def deposit(self):
pass
类SavingsAccount(的BankAccount):
def __init__(self, balance=500.0):
self.balance = balance
def deposit(self, deposit_amount):
self.balance += deposit_amount
return self.balance
if deposit_amount < 0:
raise RuntimeError('Invalid deposit amount.')
def withdraw(self, withdraw_amount):
self.balance -= withdraw_amount
return self.balance
if self.balance < 500:
raise RuntimeError('Cannot withdraw beyond the minimum account balance')
return self.balance
if withdraw_amount > self.balance:
raise RuntimeError('Cannot withdraw beyond the current account balance')
return self.balance
if withdraw_amount < 0:
raise RuntimeError('Invalid withdraw amount')
类CurrentAmount(的BankAccount): DEF 初始化(个体,平衡= 0.0): self.balance =平衡
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
'raise RuntimeError('Invalid withdraw amount。'你错过了一个右括号 – Pearley
和冒号后面的所有if语句 – languitar
这里有很多错误:如果没有缩进然后编写一些代码(即使它只是'传递'),你也不能'def'。 if语句还需要缩进和冒号(':')。你也在超过1个地方失去了你的'提升'的引用和偏执。 ''raise''后'返回''没有意义,因为你永远不会到达 –