I've read through other posts regarding this error and I thought I solved the problem, but I'm still having trouble.
I have included the necessary self
argument in the appropriate space, but I am still receiving the error:
Traceback (most recent call last):
File "...", line 30, in <module>
JohnSmith = CheckingAccount(20000)
File "...", line 18, in __init__
BankAccount.__init__(self, initBal)
TypeError: __init__() takes 1 positional argument but 2 were given
class BankAccount (object):
# define class for bank account
def __init__ (self):
# initialize bank account w/ balance of zero
self.balance = 0
def deposit (self, amount):
# deposit the given amount into account
self.balance = self.balance + amount
def withdraw (self, amount):
# withdraw the given amount from account
self.balance = self.balance - amount
def getBalance (self):
# return account balance
return self.balance
class CheckingAccount (BankAccount):
def __init__ (self, initBal):
BankAccount.__init__(self, initBal)
self.checkRecord = {}
def processCheck (self, number, toWho, amount):
self.withdraw(amount)
self.checkRecord[number] = (toWho, amount)
def checkInfo (self, number):
if self.checkRecord.has_key(number):
return self.checkRecord [ number ]
else:
return 'No Such Check'
# create checking account
JohnSmith = CheckingAccount(20000)
JohnSmith.processCheck(19371554951,'US Bank - Mortgage', 1200)
print (JohnSmith.checkInfo(19371554951))
JohnSmith.deposit(1000)
JohnSmith.withdraw(4000)
JohnSmith.withdraw(3500)
You probably want to redefine BankAccount
as
class BankAccount(object):
def __init__(self, init_bal=0):
self.balance = init_bal
# ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With