Skip to content

Commit

Permalink
Merge pull request #3558 from Jav-mol/main
Browse files Browse the repository at this point in the history
#6 -Python
  • Loading branch information
kontroldev authored May 11, 2024
2 parents 4571cb0 + 40b190b commit c1a8ec7
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions Roadmap/06 - RECURSIVIDAD/python/Jav-mol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# --- Funciones Recursivas ---

def mostrar_numeros(n:int):
""" La funcion toma un numero y le va sumando uno hasta llegar a 100.
Args:
n (int): Numero Entero menor que 100
"""
if n == 100:
return
elif n > 100 or n < 0:
return
else:
print(n)
n += 1
mostrar_numeros(n)

mostrar_numeros(101)
mostrar_numeros(-1)
mostrar_numeros(1)

""" Dificultad Extra """

# Factorial de un numero
def factorial(n:int):
print(n)

if n < 0:
return 0
elif n == 0:
return 1
else:
return n * factorial(n - 1)

print(factorial(5))


# Calcular la posicion de un numero en fibonacci
def calcular_posicion(posic:int, fibo:list=[0,1]):

if posic < fibo[-1]:
print(fibo)
return f'La posicion no es valida'
elif posic == fibo[-1]:
print(fibo)
return f'La posicion en fibonacci es {fibo.index(posic) + 1}'

fibo.append(fibo[-1]+fibo[-2])

return calcular_posicion(posic)

print(calcular_posicion(233))

0 comments on commit c1a8ec7

Please sign in to comment.