Hello,
This post is regarding the Bank Teller project in Python course.
I’m having an issue with step 7 print(check_balance):
While it should print updated variable “savings_balance” after modifying it in the make_deposit() function, it still displays the starting value.
I’m finding that it has to do with modifying global variables. Can someone help get me through this snag?
Current code:
checking_balance = 0
savings_balance = 0
def check_balance(account_type, checking_balance, savings_balance):
if account_type == "savings":
balance = savings_balance
balance_statement = "Your " + account_type + " balance is " + str(balance)
return balance_statement
elif account_type == "checking":
balance = checking_balance
balance_statement = "Your " + account_type + " balance is " + str(balance)
return balance_statement
else:
return "Unsuccessful, please enter \"checking\" or \"savings\""
print("3. "+ check_balance("checking", checking_balance, savings_balance))
print("4. "+ 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 == "savings":
savings_balance += amount
deposit_status = "succussful"
elif account_type == "checking":
checking_balance += amount
deposit_status = "succussful"
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("5.10. " + deposit_statement)
print("5.11. "+ check_balance("checking", checking_balance, savings_balance))
print("5.11. "+ check_balance("savings", checking_balance, savings_balance))
make_deposit("savings", 10, checking_balance, savings_balance)
print("7. " + check_balance("savings", checking_balance, savings_balance))
Current Result:
3. Your checking balance is 0
4. Your savings balance is 0
5.10. Deposit of 10 to your savings account was succussful
5.11. Your checking balance is 0
5.11. Your savings balance is 10
7. Your savings balance is 0
Last line should read “7. Your savings balance is 10” as the instructions are indicating.
Thank you