For a class in uni, I am required to write a function that recursively converts binary strings to its decimal representation.
The code that I wrote is as below:
def bin_to_dec(b):
"""takes an input of a string 'b' representing a
binary number and then returns its decimal representation"""
if b == 0: #base case 1: when n is 0
return "0"
elif b == 1: #base case 2: when is n is 1
return "1"
else: #recursive case
bin_to_dec_rest = bin_to_dec(b[1:])
dec_value = int(b[0])*2 + bin_to_dec_rest
return dec_value
Upon doing so, I got the following error in my console: Recusion error
Could someone please explain what this means, and why it may have occurred?