Pregunta

In writing a recursive function that counts string length, I'm getting a not enough arguments error, when It seems I put in enough. Why is that?

def lenRecur(aStr,Len,n):
    if aStr[n+1: ] == ' ':
        return 1
    else:
        Len=Len + lenRecur(aStr[n+1:])
        return Len
s='abc'
lenRecur(s , 0 , 0)

output: TypeError: lenRecur() takes exactly 3 arguments (1 given)
¿Fue útil?

Solución

The line:

Len=Len + lenRecur(aStr[n+1:])

is only passing 1 argument.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top