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?
2((-2**a)/(2**a)+2)supposed to do then? Are you forgetting a*multiplication there?b = 0line; that's indeed going to lead to a new error.**is the exponentiation operator and not what I am talking about. I am talking about the2at the start. I think you meant to multiply by 2 here.