Someone please help me out. I am a python newbie


#1

I am getting failure errors in the deposit and withdraw methods, in both CurrentAccount and SavingsAccount classes. Here's my code.

class BankAccount():
	def __init__(self, balance):
		self.balance = balance
	def deposit(self, amount):
		self.balance +=amount
		return balance
		
	def withdraw(self, amount):
		self.balance -=amount
		return self.balance

class SavingsAccount(BankAccount):	
	def __init__(self):
		self.minimum_balance = 500
	def deposit(self, amount):
		if amount < 0:
			return "Invalid deposit amount"
		else:
			BankAccount.deposit(self, amount)
	def withdraw (self, amount):
		if self.balance - amount < self.minimum_balance:
			return "Cannot withdraw beyond the minimum account balance"
		elif amount > self.balance:
			return "Cannot withdraw beyond the current account balance"
		elif amount < 0:
			return "Invalid withdraw amount"
		else:
			BankAccount.withdraw(self, amount)
	
class CurrentAccount(BankAccount):
	def __init__(self):
		self.balance = 0
	def deposit(self, amount):
		if amount < 0:
			return "Invalid deposit amount"
		else:
			BankAccount.deposit(self, amount)
	def withdraw (self, amount)
		if amount < 0:
		 return "Invalid withdraw amount"
		elif amount > self.balance:
			return "Cannot withdraw beyond the current account balance"
		else:
			BankAccount.withdraw(self, amount)

#2

If you're getting error messages then the thing to do with those is to read them and consider the problem that they are describing, and asking yourself why that problem wouldn't occur, followed by comparing that reason to what the code currently is, remove that difference and run again.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.