My first project - Bank teller

Hi everyone,

I’m a total newbie at coding and so excited to join codeacademy community!

Please find herafter my first project for the Analyze Financial Data with Python path.


#1 Initializing savings and checking account values

checking_balance = 0

savings_balance = 0

#2 Create a function to check the Balance

def check_balance(account_type, checking_balance, savings_balance):

    if account_type == 'savings':

        balance = savings_balance

    elif account_type == 'checking':

        balance = checking_balance

    else:

        'Unsuccessful, please enter \'checking\' or \'savings\''

    balance_statement = 'Your ' + account_type +' balance is ' + str(balance)

    return balance_statement

#3 Calling and Printing the check_balance() function for Checking Account

print(check_balance('checking',checking_balance,savings_balance))

#4 Calling and Printing the check_balance() function for Savings Account

print(check_balance('savings',checking_balance,savings_balance))

#5 Create a function to make a deposit

def make_deposit(account_type,amount,checking_balance,savings_balance):

    deposit_status = ''

    if amount > 0:

        if account_type == 'savings':

            savings_balance += amount

            deposit_status = 'successful'

        elif account_type == 'checking':

            checking_balance += amount

            deposit_status = 'successful'

        else:

            deposit_status = 'Error'

    else:

        deposit_status = 'unsuccessful, please enter an amount greater than 0'

    deposit_statement = 'Deposit of '+str(amount)+' to your '+account_type+' account was '+deposit_status

    print(deposit_statement)

    return savings_balance, checking_balance

#6 Call deposit function and make a savings deposit

savings_balance, checking_balance = make_deposit('savings',10,checking_balance,savings_balance)

#7 Print savings balance call after making a savings deposit

print(check_balance('savings',checking_balance,savings_balance))

#8 Call deposit function and make a checking deposit

savings_balance, checking_balance = make_deposit('checking',200,checking_balance,savings_balance)

#9 Print checking balance call after making a checking deposit

print(check_balance('checking',checking_balance,savings_balance))

#10 Create a function to make a withdrawal

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 savings_balance >= amount:

            savings_balance -= amount

            withdrawal_status = 'successful'

        else:

            withdrawal_status = fail

    if account_type == 'checking':

        if checking_balance >= amount:

            checking_balance -= amount

            withdrawal_status = 'successful'

        else:

            withdrawal_status = fail

    else:

        account_type == 'Error'

    

    withdrawal_statement = 'Withdrawal of '+str(amount)+' from your '+account_type+' was '+withdrawal_status

    print(withdrawal_statement)

    return savings_balance,checking_balance

#11 Call withdrawal function and make a savings withdrawal

make_withdrawal('savings', 11,checking_balance,savings_balance)

#12 Print savings balance call, after making a savings withdrawal

check_balance('savings', checking_balance, savings_balance)

#13 Call withdrawal function and make a checking withdrawal

savings_balance, checking_balance = make_withdrawal('checking',170,checking_balance,savings_balance)

#14 Print checking balance call, after making a checking withdrawal

print(check_balance('checking',checking_balance,savings_balance))

#15 Create a function to make a transfer between accounts

def acc_transfer(acc_from, acc_to, amount, checking_balance, savings_balance):

    transaction_status = ''

    trans_error = 'unsuccessful, please enter amount less than '

    if acc_from == 'savings' and acc_to == 'checking':

        if amount > savings_balance:

            transaction_status = trans_error + str(savings_balance)

        else:

            savings_balance -= amount

            checking_balance += amount

            transaction_status = 'successful'

    elif acc_from == 'checking' and acc_to == 'savings':

        if amount > checking_balance:

            transaction_status = trans_error + str(checking_balance)

        else:

            savings_balance += amount

            checking_balance -= amount

            transaction_status = 'successful'

    else:

        transaction_status == 'unsuccessful, please enter \'checking\' or \'savings\''

    

    transaction_statement = 'Transfer of ' + str(amount) + ' from your ' + acc_from + ' to your ' + acc_to + ' account was '+ transaction_status

   

    print(transaction_statement)

  

    return savings_balance, checking_balance

#16 Call transfer function and make a checking to savings transfer

(checking_balance, savings_balance) = acc_transfer('checking', 'savings', 40, checking_balance, savings_balance)

#17 Print checking balance after making a checking to savings transfer

print(check_balance('checking',checking_balance,savings_balance))

#18 Print savings balance after making a checking to savings transfer

print(check_balance('savings',checking_balance,savings_balance))

#19 Call transfer function and make a savings to checking transfer

savings_balance, checking_balance = acc_transfer('savings','checking',5,checking_balance,savings_balance)

#20 Print checking balance after making a savings to checking transfer

print(check_balance('checking',checking_balance,savings_balance))

#21 Print saving balance after making a savings to checking transfer

print(check_balance('savings',checking_balance,savings_balance))``

Cheers

gr2099ad

Hello @gr2099ad, welcome to the forums! Could you post the requirements for the task, please? Other than that, the naming conventions looks good, and the code seems to strike the right balance between readability and conciseness. Since you are (probably) doing this in Python 3.x, you could consider using a different type of string formatting (other than concatenation-as it is memory expensive, and takes longer to write). My personal favourite is fstring. There are 3 other major ways in which to do it, though, as explained in this article.

Hi @codeneutrino,

thanks for your feedback.

These were the requirements:

In this project, you will make a system that emulates the transactions that are carried out by either a bank teller or an ATM machine. You will utilize entry-level Python syntax, operands and concepts to implement the following five features:

Return the balance that the customer has in the bank
Allow the customer to make a deposit to their bank account
Allow the customer to make a withdrawal to their bank account
Allow the customer to decide whether to make the transaction with checking or savings account
Allow the customer to make a transfer between savings and checking account

Thanks for the tip on fstring. I will try to incorporate in the next code as it looks more smooth and readable.

Thank you

1 Like