Bank Teller Project

Is it possible to write the check_balance function so that you don’t have to call it within a print statement every time you check the balance?

Instead of: print(check_balance( ‘checking’, checking_balance, savings_balance))

Would this work: (check_balance(‘checking’, checking_balance, savings_balance)

1 Like

Yes, you could use either return "" or return

def check_balance(account_type, checking_balance, savings_balance):
    if account_type == 'savings':
        balance = savings_balance
    elif account_type == 'checking':
        balance = checking_balance
        print('Unsuccessful, please enter \"checking\" or \"savings\"')
    balance_statement = 'Your ' + account_type + ' balance is $' + str(balance) + ' .'

That’s because anything after a return statement doesn’t get executed, if I don’t use return there, it will (only if both if and elif didn’t run) print out the unsuccessful one as well as the balance_statement

In this case a print is the better option since returning a message is most likely going to be printed out, but in cases where the value is a number or boolean or in some cases a string, return is probably a better solution since after that you can do whatever you want to do with it.
I hope this helps :grinning: