【发布时间】:2017-08-07 08:25:53
【问题描述】:
我已经编写了以下代码,但是当我尝试运行它时,我得到一个 文件“C:\Users\Moses\Desktop\test.py”,第 4 行 def 存款(自己): ^ IndentationError: 预期一个缩进块 错误。我需要这方面的帮助。
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 init(self, balance=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.你缺少右括号 -
所有 if 语句后加一个冒号
-
这里有很多错误:如果不缩进并编写一些代码(即使只是
pass),您就无法执行def。if语句还需要缩进和冒号 (:)。您在Raise上也有不止一个地方缺少引号和括号。在raiseing 之后returning 毫无意义,因为你永远不会到达那里
标签: python