Bank_teller_project

Hey guys, please have a dabble at this if you’re bored or have time - I think it’s all correct.

I noticed quite a few errors in the instructions… any idea how that can get edited for future users?

Hey @leufel, welcome to the forums!

I would suggest submitting a bug report in the instructions or lessons that have errors in them. That way, the team at Codecademy can see and fix these errors.

I am getting a problem with the global variables. They are not getting updated in this project. Could someone let me know how to fix this? I have seen the solution and there seems to be nothing wrong.

Is there a particular lesson in which you are encountering this problem? Please post a link to that exercise, as well as the code you have written thus far.

If this is a Python project then you should know we cannot update global variables from within a function unless we bind them.

var = 42

def foo():
    global var

Hello! I am currently doing the Bank Teller project in the skill course Analyze Financial Data with Python. It requires you to code on a Jupyter Notebook. I don’t know how to share the code for my Jupyter file so could you suggest a way to do this. And I tried this above method but it gave an error citing Invalid Syntax.

Hello everyone, I’m tackling this project right now, but I don’t think my check_balance() function is working properly. Code below:

checking_balance - 0
savings_balance = 0

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 "Unsuccessful, please enter \"checking\" or \"savings\""
    balance_statement = "Your " + account_type + " balance is "+ str(balance)
    return balance_statement

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 = "Unsuccessful, please enter \"checking\" or \"savings\""
    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 checking_balance, savings_balance

print(make_deposit("savings", 10, checking_balance, savings_balance)) ---> this gives a savings_balance of 10. 

print(check_balance("savings", checking_balance, savings_balance)) ---> Now this gives 0 instead of 10.

Any ideas? Thanks !

Same with me!

There is a problem with my make_deposit() function

Do you remember the variables you set to 0 in the beginning of this challenge? You didn’t update them at all! They are still zero outside the function you created.

You need to update the global “checking_balance” and “savings_balance” when you call the “make_deposit()” function.

You should change your last two print statements with these:

checking_balance, savings_balance = make_deposit("savings",10,checking_balance,savings_balance)
print(check_balance("savings",checking_balance,savings_balance))

First line makes the deposit, returns the value and updates the global balance variables.
Second line just prints the balance status.

Does that make sense?

Thanks for your help! I updated the lines of code to:

savings_balance = make_deposit(“savings”, 10, checking_balance, savings_balance)
print(check_balance(“checking”, checking_balance, savings_balance))
print(check_balance(“savings”, checking_balance, savings_balance))
checking_balance = make_deposit(“checking”, 200, checking_balance, savings_balance)
print(check_balance(“checking”, checking_balance, savings_balance))
print(check_balance(“savings”, checking_balance, savings_balance))

Now I’m getting a strange result when I run the code:

Deposit of 10 to your savings account was successful.
Your checking balance is 0.
Your savings balance is (0, 10).
Deposit of 200 to your checking account was successful.
Your checking balance is (200, (0, 10)).
Your savings balance is (0, 10).

Here’s my complete code so far:

checking_balance = 0
savings_balance = 0


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 "Unsuccessful, please enter \"checking\" or \"savings\""

    balance_statement = "Your " + account_type + " balance is " + str(balance) + "."
    return balance_statement


print(check_balance("checking", checking_balance, savings_balance))
print(check_balance("savings", checking_balance, savings_balance))


def make_deposit(account_type, amount, checking_balance, savings_balance):
    deposit_status = str()

    if amount > 0:
        if account_type == "checking":
            checking_balance += amount
            deposit_status = "successful"
        elif account_type == "savings":
            savings_balance += amount
            deposit_status = "successful"
        else:
            deposit_status = "unsuccessful, please enter \"checking\" or \"savings\""
    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 checking_balance, savings_balance


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

print(check_balance("checking", checking_balance, savings_balance))
print(check_balance("savings", checking_balance, savings_balance))

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

print(check_balance("checking", checking_balance, savings_balance))
print(check_balance("savings", checking_balance, savings_balance))

FIXED THIS PROBLEM WITH THE FOLLOWING CODE (LOOK FOR # COMMENTED LINES):

checking_balance = 0
savings_balance = 0


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 "Unsuccessful, please enter \"checking\" or \"savings\""

    balance_statement = "Your " + account_type + " balance is " + str(balance) + "."
    return balance_statement


print(check_balance("checking", checking_balance, savings_balance))
print(check_balance("savings", checking_balance, savings_balance))


def make_deposit(account_type, amount, checking_balance, savings_balance):
    deposit_status = str()

    if amount > 0:
        if account_type == "checking":
            checking_balance += amount
            balance = checking_balance # CREATED VARIABLE
            deposit_status = "successful"
        elif account_type == "savings":
            savings_balance += amount
            balance = savings_balance # CREATED VARIABLE
            deposit_status = "successful"
        else:
            deposit_status = "unsuccessful, please enter \"checking\" or \"savings\""
    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 balance # CHANGED TO VARIABLE


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

print(check_balance("checking", checking_balance, savings_balance))
print(check_balance("savings", checking_balance, savings_balance))

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

print(check_balance("checking", checking_balance, savings_balance))
print(check_balance("savings", checking_balance, savings_balance))