The reason is related to the priority of the operator. Beeftrack operators have lower priority than arithmetic.
The default x << 1 + recursion(x - 1)is considered x << (1 + recursion(x - 1)).
You can fix the problem by overriding the default priority using parentheses.
def recursion(x):
if x == 0:
return 0
else:
return (x << 1) + recursion(x - 1)
print(recursion(3))
source
share