Bank Teller Project - A bit confused when assigning multiple variables

Hi guys.
One quick question, as I noticed in this code at the last line I’ll have to assign the two variables in the order of “savings” comes first and then “checking”.
If I went the other way around, the variables wouldn’t get updated.
Does this have something to do with sequences of the boolean statement(line 4) or the return results(line 19)?

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 savings_balance, checking_balance

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

https://www.codecademy.com/paths/finance-python/tracks/introduction-to-python-for-finance/modules/introduction-to-jupyter-notebooks/informationals/bank-teller

Hello, @pinker, and welcome to the forums.

That’s exactly it. It has nothing to do with the names of the variables assigned to the return values, only their position (order). The first value returned is assigned to the first variable listed in your multiple assignment. The second value returned is assigned to the second variable in the multiple assignment.

Silly example:
def many_returns(n):
    r_v1 = n * 2
    r_v2 = n * 3
    r_v3 = n * 4
    r_v4 = n * 5
    r_v5 = n * 6
    return r_v1, r_v2, r_v3, r_v4, r_v5
    
one, two, three, four, five = many_returns(5)

print(f'one: {one}\ntwo: {two}\nthree: {three}\nfour: {four}\nfive: {five}\n')

#the names don't matter
#this is the same:

def many_returns2(sky):
    cat = sky * 2
    dog = sky * 3
    mouse = sky * 4
    potato = sky * 5
    jelly = sky * 6
    #the order does matter:
    return dog, potato, jelly, mouse, cat
    
the, quick, brown, fox, jumps = many_returns2(5)

print(f'the: {the}\nquick: {quick}\nbrown: {brown}\nfox: {fox}\njumps: {jumps}')

Output:

one: 10
two: 15
three: 20
four: 25
five: 30

the: 15
quick: 25
brown: 30
fox: 20
jumps: 10

Got it. Thanks! Silly example was helpful xd

1 Like