Reputation: 13
I imported a json file and created a while loop for rice bank account for super rice. I create def under parent code but encountered an error: TypeError: withdraw_money() missing 1 required positional argument: 'amount'. I am also trying to put new values for new week per each subclass that will append 500 for Super Rice Account and Prepaid, 0 for Normal Rice A. I am stuck with SuperRiceAccount.withdraw_money(amount) because of the error and I still need to figure out the function for the new week. Can anyone help me?
Here'a my code below
class BaseAccount:
def __init__(self, account_id, account_type, full_name, birthday, balance,amount=500):
self.account_id = account_id
self.account_type = account_type
self.full_name = full_name
self.birthday = birthday
self.balance = balance
self.amount = amount
def account_info(self):
for p in data ['accounts']:
print('You have successfully withdrawn 500 grams from the account.')
print('Account ID:' + p['account_id'])
print('Account Type:' + p['account_type'])
print('Full Name:' + p['full_name'])
print('Birthday:' + p['birthday'])
print('Balance: ' + self.balance + ' left')
def withdraw_money(self, amount):
self.balance = self.balance - amount(500)
for p in data['accounts']:
print('You have successfully withdrawn 500 grams from the account.')
print('Account ID:' + p['account_id'])
print('Account Type:' + p['account_type'])
print('Full Name:' + p['full_name'])
print('Birthday:' + p['birthday'])
print('Balance: ' + self.balance + ' left')
def new_week(self):
return
class SuperRiceAccount(BaseAccount):
def __init__(self, account_id, account_type, full_name, birthday, balance):
super().__init__(account_id, account_type, full_name, birthday, balance)
if self.balance >= 2000:
print ('You still have ', self.balance, ' left.')
else:
print('You do not have enough balance.')
def new_week(self):
if initial_balance < 2000:
self.balance = self.balance + 500
print('Your new balance is ', self.balance, ' left')
while True:
print('( 1 ) List All Accounts')
print('( 2 ) Withdraw Rice from an Account')
print('( 3 ) New Week')
print('( 4 ) Exit')
print('')
option = int(input('Enter your choice: '))
if option == 1:
for p in data['accounts']:
print('Account ID:'+ p['account_id'])
print('Account Type:' + p['account_type'])
print('Full Name:' + p['full_name'])
print('Birthday:' + p['birthday'])
print('Balance:'+ str(p["balance"]))
print('')
if option == 2:
print('')
i = input('Enter Account ID:')
print('')
for p in data['accounts']:
if p ['account_id'] == i:
print('Account ID:' + p['account_id'])
print('Account Type:' + p['account_type'])
print('Full Name:' + p['full_name'])
print('Birthday:' + p['birthday'])
print('Balance: ' + str(p["balance"]) + ' left')
print('')
else:
amount = input('Input 500 to withdraw 500 grams from this account:')
SuperRiceAccount.withdraw_money(amount)
SuperRiceAccount.account_info(amount)
for p in data['accounts']:
print('Account ID:' + p['account_id'])
print('Account Type:' + p['account_type'])
print('Full Name:' + p['full_name'])
print('Birthday:' + p['birthday'])
print('Balance:' + str(p["balance"]))
print('')
Upvotes: 1
Views: 38
Reputation: 6298
You should use a SuperRiceAccount
object when calling the method withdraw_money
.
What happens is that when you call that function the amount is passed as the first argument self
and therefore the second argument amount
is missing.
Fix it by initializing:
bank = SuperRiceAccount([PASS HERE INITIALIZATION PARAMETERS])
and calling with:
bank.withdraw_money(amount)
bank.account_info(amount)
Upvotes: 0