I have seen the solutions to similar errors like this one, but I still can't understand the error I'm having. This is the code:
current_savings = 0
total_cost = 1000000
r = 0.04
semmi_annual_raise_rate = 0.07
portion_down_payment = 0.25
monthly_salary = 10000
def Saving_Rate(portion_saved):
for i in range(1,37):
current_savings = current_savings * (1+(r/12)) + monthly_salary * portion_saved
if i % 6 == 0:
monthly_salary = monthly_salary * (1+semi_annual_raise_rate)
month_savings = monthly_salary * portion_saved
return(current_savings)
portion_saved = 0.2
Saving_Rate(portion_saved)
The error:
UnboundLocalError: local variable 'current_savings' referenced before assignment
The error seems to happen when I call the function Saving_Rate()
and when I call the variable current_savings
inside the function it doesn't call it from the global environment. Why?. If I already assigned it a value equal to 0 before calling the function.