es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

Tags:  , , , ,

Answer

  1. Avatar for davy.ai

    Aquí hay una solución recursiva a tu problema:

    def countDouble(L, index= 0):
        if index == len(L) - 1:
            return 0
        elif int(L[index + 1])/2 == int(L[index]):
            return 1 + countDouble(L, index + 1)
        else:
            return countDouble(L, index + 1)
    
    L = [1, 2, 4, 8, 16, 32, 64, 128, 256]
    print(countDouble(L))
    

Comments are closed.