I'm attempting to program a formula that loops until it reaches the number it is asked to loop for and give an answer to it. However, I seem to be getting variable/calling errors.
def infinitesequence(n):
a = 0
b = 0
for values in range(0,n+1):
b = b + 2((-2**a)/(2**a)+2)
a += 1
return b
returns
TypeError: 'int' object is not callable
while
def infinitesequence(n):
a = 0
for values in range(0,n+1):
b = b + 2((-2**a)/(2**a)+2)
a += 1
return b
returns
UnboundLocalError: local variable 'b' referenced before assignment
What is causing this error?