Ich habe den folgenden Code geschrieben, aber wenn ich versuche, es auszuführen, erhalte ich eine Datei "C: \ Benutzer \ Moses \ Desktop \ test.py", Zeile 4 def deposit (self): ^ IndentationError: erwartet einen eingerückten Block Fehler. Ich brauche Hilfe dabei.Python löste einen Einrückungsfehler
class BankAccount(object):
def withdraw(self):
pass
def deposit(self):
pass
Klasse Savings (Bankkonto):
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')
Klasse CurrentAmount (Bankkonto): def init (self, Balance = 0,0): self.balance = 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
Ich brauche ein wenig Hilfe mit dem Eindruckfehler, um zu wissen, was es ist und wie man es löst. Ich bin neu in Python
'Raise RuntimeError ('Ungültiger Auszahlungsbetrag.'Sie vermissen eine schließende Klammer – Pearley
und einen Doppelpunkt nach allen if-Anweisungen – languitar
Eine Menge Fehler hier: Sie können nicht' def' ohne dann Einrücken und Schreiben von etwas Code (auch wenn es nur 'pass') tun. 'if'-Anweisungen erfordern auch Einrückung und einen Doppelpunkt (': '). dir fehlen auch Anführungszeichen und Klammern zu deinem 'Raise' an mehr als einem Ort. Es gibt keinen Sinn in 'return' nach 'raise'ing, weil du nie dorthin kommst –