Last active
September 4, 2017 02:42
-
-
Save lumiobrie/1b1918892c746724e7aec97fc0a1f49f to your computer and use it in GitHub Desktop.
Librería con dos funciones. Una para determinar si un número entero es primo y otra para calcular la suma de los dígitos de un número entero
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
def esPrimo(num): | |
if (isinstance(num,str) or num < 2 or num % 2 == 0) and num !=2: | |
return False | |
for divisor in range(3, num//2 + 1, 2): | |
if num % divisor == 0: | |
return False | |
return True | |
def sumarDigitos(num): | |
if isinstance(num,str) or num < 0: | |
return 0 | |
suma = 0 | |
while(num != 0): | |
suma += num % 10 | |
num //= 10 | |
return suma |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment