Created
December 6, 2018 12:15
-
-
Save vfrico/58e75f099f7bec6da470336b82b6d9bb to your computer and use it in GitHub Desktop.
Obtiene los divisores de un número (Versión recursiva)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
def divisor_helper(n, i): | |
if i == 0: | |
return [] | |
elif n % i == 0: | |
recursion = [i] + divisor_helper(n, i-1) | |
return recursion | |
else: | |
return divisor_helper(n, i-1) | |
def divisores(n): | |
if n == 0: | |
return [0] | |
elif n == 1: | |
return [1] | |
else: | |
return divisor_helper(n, n) | |
print(divisores(12)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment