I am working through an off-platform Bank Teller project and I am confused on one particular concept.
One small change to the code results in incorrect output, and I am wondering how the omission affects the logic.
Apologies in advance if this is the wrong place to post.
Correct answer should be:
#Block A initial checking_account_balance and savings_account_balance checking_balance = 200 savings_balance = 10
#Block B check_balance definition def check_balance(account_type, checking_balance, savings_balance): if account_type == "savings": balance = savings_balance elif account_type == "checking": balance = checking_balance else: return acc_error balance_statement = "Your " + account_type + " balance is " + str(balance) return balance_statement
#Block C check checking and savings balance call print(check_balance("checking",checking_balance,savings_balance)) print(check_balance("savings",checking_balance,savings_balance))
#Block D withdrawal function def make_withdrawal(account_type,amount,checking_balance,savings_balance): withdrawal_status = "" fail = "unsuccessful, please enter amount less than balance" if account_type == "savings": if amount <= savings_balance: savings_balance -= amount withdrawal_status = "successful" else: withdrawal_status = fail elif account_type == "checking": if amount <= checking_balance: checking_balance -= amount withdrawal_status = "successful" else: withdrawal_status = fail else: withdrawal_status = acc_error withdrawal_statement = "Withdrawal of "+ str(amount) + " from your " + account_type + " account was " + withdrawal_status + "." #print withdrawal statement print(withdrawal_statement) return savings_balance, checking_balance
#Block E update bank account after checking withdrawal savings_balance, checking_balance = make_withdrawal("checking",170,checking_balance,savings_balance)
#Block F check checking balance call after withdrawal print(check_balance("checking",checking_balance,savings_balance))
The only difference I had in my coding is at Block E, I failed to include
savings_balance, checking_balace = … the correct ending balance should be 30, my incorrect result shows 200
My logic being I already had a return savings_balance, checking_balance in Block D which registered the running total, so block F should reflect the correct balance.
I have a feeling I might misunderstood what “return” does in general. Super grateful if someone can shed some light!