del lista_suma[-1] #Borro el último de la lista del lista[0] #Borro el primero de la lista #Comparo las listas for i in range(len(lista)): if lista[i] != lista_suma[i]: sociables = False break #Comparo el primero y el último if primero != ultimo: sociables = False return sociables # –- Programa principal –- # Ejecutar el test sólo al ejecutar el fichero (y no al importarlo) if __name__ == '__main__': # Código para ejecutar la función con los datos de prueba # ¡¡SE PUEDE COMENTAR LÍNEAS PERO NO MODIFICARLAS!! test(son_sociables([220, 284]) == True) test(son_sociables([14288, 15472, 14536, 14264, 12496]) == True) test(son_sociables([14316, 19116, 31704, 47616, 83328, 177792, 295488, 629072, \ 589786, 294896, 358336, 418904, 366556, 274924, 275444, \ 243760, 376736, 381028, 285778, 152990, 122410, 97946, \ 48976, 45946, 22976, 22744, 19916, 17716]) == True) test(son_sociables([28158165, 29902635, 30853845, 29971755]) == True)
[3,1,2]] matriz3=[[1,2,3,4], \ [2,1,4,3], \ [3,4,1,2], \ [4,3,2,1]] matriz4=[[1,2,3,4], \ [3,4,1,2], \ [4,3,2,1], \ [2,1,4,3]] matriz5=[[1,2,3], \ [0,3,1], \ [3,1,2]] matriz6=[[1,2,3], \ [2,3,4], \ [3,1,2]] matriz7=[[1,2,3], \ [2,3,1], \ [1,2,3]] matriz8=[[1,2,3,4], \ [2,1,4,3], \ [3,4,1,2], \ [1,3,2,4]] test(es_cuadrado_latino(matriz2) == True) test(es_cuadrado_latino(matriz3) == True) test(es_cuadrado_latino(matriz4) == True) test(es_cuadrado_latino(matriz5) == False) test(es_cuadrado_latino(matriz6) == False) test(es_cuadrado_latino(matriz7) == False) test(es_cuadrado_latino(matriz8) == False)
lista_resultado = [] #Creamos la lista llevo = 0 for i in range(len(lista1) - 1, -1, -1): suma = lista1[i] + lista2[i] + llevo if suma > 9: llevo = 1 else: llevo = 0 lista_resultado = [suma % 10] + lista_resultado if llevo == 1: lista_resultado = [llevo] + lista_resultado return lista_resultado # –- Programa principal –- # Ejecutar el test sólo al ejecutar el fichero (y no al importarlo) if __name__ == '__main__': # Código para ejecutar la función con los datos de prueba # ¡¡SE PUEDE COMENTAR LÍNEAS PERO NO MODIFICARLAS!! test(sumar_lista_digitos([3, 5, 4], [1, 6, 3]) == [5, 1, 7]) test(sumar_lista_digitos([9, 9, 9], [9, 9, 9]) == [1, 9, 9, 8]) test(sumar_lista_digitos([9, 9, 9], [1]) == None) test(sumar_lista_digitos([], [9, 9, 9]) == None) test(sumar_lista_digitos([7, 9, 9, 9], [2, 0, 0, 0]) == [9, 9, 9, 9]) test(sumar_lista_digitos([9, 9, 9, 9], [2, 0, 0, 0]) == [1, 1, 9, 9, 9])
nueva = nueva + cadena[i] if contador == 3: if nueva == comparar: encontrado = encontrado + 1 contador = 0 nueva = "" if encontrado > maximo: maximo = encontrado else: encontrado = 0 contador = 0 nueva = "" if maximo == 0: return else: return maximo # –- Programa principal –- # Ejecutar el test sólo al ejecutar el fichero (y no al importarlo) if __name__ == '__main__': # Código para ejecutar la función con los datos de prueba # ¡¡SE PUEDE COMENTAR LÍNEAS PERO NO MODIFICARLAS!! test(expansion_triplete_CAG('GACGAC') == None) test(expansion_triplete_CAG('CAGCAG') == 2) test(expansion_triplete_CAG('TACGTACGTAT') == None) test(expansion_triplete_CAG('CAGCAGTACCTCAGACGT') == 2) test(expansion_triplete_CAG('GATCGATCGATGCTAGCTAGCGCATC') == None) test(expansion_triplete_CAG('TACTCAGCAGGATGCAGCAGCAGCAGCAG') == 5)
suma_n2 = 0 lista_n1 = divisores(n1) lista_n2 = divisores(n2) del lista_n1[-1] del lista_n2[-1] for elem in lista_n1: suma_n1 = suma_n1 + elem for elem in lista_n2: suma_n2 = suma_n2 + elem if suma_n1 == n2 and suma_n2 == n1: amigos = True return amigos # –- Programa principal –- # Ejecutar el test sólo al ejecutar el fichero (y no al importarlo) if __name__ == '__main__': # Código para ejecutar la función con los datos de prueba # ¡¡SE PUEDE COMENTAR LÍNEAS PERO NO MODIFICARLAS!! test(son_amigos(30, 42) == False) test(son_amigos(42, 30) == False) test(son_amigos(220, 284) == True) test(son_amigos(284, 220) == True) test(son_amigos(2620, 2924) == True) test(son_amigos(6368, 6232) == True)
# -*- coding: utf-8 -*- from modulo_test import test def divisores(numero): lista = [] for i in range(1, numero): if numero % i == 0: lista.append(i) lista.append(numero) return lista # –- Programa principal –- # Ejecutar el test sólo al ejecutar el fichero (y no al importarlo) if __name__ == '__main__': # Código para ejecutar la función con los datos de prueba # ¡¡SE PUEDE COMENTAR LÍNEAS PERO NO MODIFICARLAS!! test(divisores(10) == [1, 2, 5, 10]) test(divisores(9) == [1, 3, 9]) test(divisores(10) == [1, 2, 5, 10]) test(divisores(30) == [1, 2, 3, 5, 6, 10, 15, 30]) test(divisores(35) == [1, 5, 7, 35]) test(divisores(49) == [1, 7, 49])
# -*- coding: utf-8 -*- from modulo_test import test def es_narcisista (n): es_narcista = True comparar = n cifra = len(str(n)) suma_potencia = 0 while es_narcista and n != 0: suma_potencia = suma_potencia + (n%10)**cifra n = n//10 if suma_potencia != comparar: es_narcista = False return es_narcista # –- Programa principal –- # Ejecutar el test sólo al ejecutar el fichero (y no al importarlo) if __name__== '__main__': # Código para ejecutar la función con los datos de prueba # ¡¡SE PUEDE COMENTAR LÍNEAS PERO NO MODIFICARLAS!! test(es_narcisista(1) == True) test(es_narcisista(153) == True) test(es_narcisista(154) == False) test(es_narcisista(406) == False) test(es_narcisista(407) == True) test(es_narcisista(8208) == True) test(es_narcisista(92727) == True) test(es_narcisista(548834) == True) test(es_narcisista(24678051) == True)
lista_resultado = [] # Creamos la lista llevo = 0 for i in range(len(lista1) - 1, -1, -1): suma = lista1[i] + lista2[i] + llevo if suma > 9: llevo = 1 else: llevo = 0 lista_resultado = [suma % 10] + lista_resultado if llevo == 1: lista_resultado = [llevo] + lista_resultado return lista_resultado # –- Programa principal –- # Ejecutar el test sólo al ejecutar el fichero (y no al importarlo) if __name__ == "__main__": # Código para ejecutar la función con los datos de prueba # ¡¡SE PUEDE COMENTAR LÍNEAS PERO NO MODIFICARLAS!! test(sumar_lista_digitos([3, 5, 4], [1, 6, 3]) == [5, 1, 7]) test(sumar_lista_digitos([9, 9, 9], [9, 9, 9]) == [1, 9, 9, 8]) test(sumar_lista_digitos([9, 9, 9], [1]) == None) test(sumar_lista_digitos([], [9, 9, 9]) == None) test(sumar_lista_digitos([7, 9, 9, 9], [2, 0, 0, 0]) == [9, 9, 9, 9]) test(sumar_lista_digitos([9, 9, 9, 9], [2, 0, 0, 0]) == [1, 1, 9, 9, 9])
# -*- coding: utf-8 -*- from modulo_test import test def divisores (numero): lista = [] for i in range(1,numero): if numero%i == 0: lista.append(i) lista.append(numero) return lista # –- Programa principal –- # Ejecutar el test sólo al ejecutar el fichero (y no al importarlo) if __name__== '__main__': # Código para ejecutar la función con los datos de prueba # ¡¡SE PUEDE COMENTAR LÍNEAS PERO NO MODIFICARLAS!! test(divisores(10) == [1, 2, 5, 10]) test(divisores(9) == [1, 3, 9]) test(divisores(10) == [1, 2, 5, 10]) test(divisores(30) == [1, 2, 3, 5, 6, 10, 15, 30]) test(divisores(35) == [1, 5, 7, 35]) test(divisores(49) == [1, 7, 49])
nueva = nueva + cadena[i] if contador == 3: if nueva == comparar: encontrado = encontrado + 1 contador = 0 nueva = "" if encontrado > maximo: maximo = encontrado else: encontrado = 0 contador = 0 nueva = "" if maximo == 0: return else: return maximo # –- Programa principal –- # Ejecutar el test sólo al ejecutar el fichero (y no al importarlo) if __name__== '__main__': # Código para ejecutar la función con los datos de prueba # ¡¡SE PUEDE COMENTAR LÍNEAS PERO NO MODIFICARLAS!! test(expansion_triplete_CAG('GACGAC') == None) test(expansion_triplete_CAG('CAGCAG') == 2) test(expansion_triplete_CAG('TACGTACGTAT') == None) test(expansion_triplete_CAG('CAGCAGTACCTCAGACGT') == 2) test(expansion_triplete_CAG('GATCGATCGATGCTAGCTAGCGCATC') == None) test(expansion_triplete_CAG('TACTCAGCAGGATGCAGCAGCAGCAGCAG') == 5)
## porcentaje = 100 ## contador = 0 ## resultado = 0 ## for caracter in cadena: ## if caracter == "G" or caracter == "C": ## contador = contador + 1 ## resultado = round(contador / len(cadena) * porcentaje,2) ## return resultado def contenido_GC(cadena): contador = 0 distinto = 0 resultado = 0 for caracter in cadena: if caracter == "G" or caracter == "C": contador = contador + 1 resultado = round(100 / len(cadena) * (len(cadena) - contador),2) return resultado # –- Programa principal –- # Ejecutar el test sólo al ejecutar el fichero (y no al importarlo) if __name__== '__main__': # Código para ejecutar la función con los datos de prueba # ¡¡SE PUEDE COMENTAR LÍNEAS PERO NO MODIFICARLAS!! test(contenido_GC('GCGC') == 100.0) test(contenido_GC('CGCG') == 100.0) test(contenido_GC('GACGAC') == 66.67) test(contenido_GC('TACGTACGTAT') == 36.36) test(contenido_GC('CAGTACTACCTCAGACGT') == 50.0) test(contenido_GC('GATCGATCGATGCTAGCTAGCGCATC') == 53.85)
del lista_suma[-1] #Borro el último de la lista del lista[0] #Borro el primero de la lista #Comparo las listas for i in range(len(lista)): if lista[i] != lista_suma[i]: sociables = False break #Comparo el primero y el último if primero != ultimo: sociables = False return sociables # –- Programa principal –- # Ejecutar el test sólo al ejecutar el fichero (y no al importarlo) if __name__== '__main__': # Código para ejecutar la función con los datos de prueba # ¡¡SE PUEDE COMENTAR LÍNEAS PERO NO MODIFICARLAS!! test(son_sociables([220, 284]) == True) test(son_sociables([14288, 15472, 14536, 14264, 12496]) == True) test(son_sociables([14316, 19116, 31704, 47616, 83328, 177792, 295488, 629072, \ 589786, 294896, 358336, 418904, 366556, 274924, 275444, \ 243760, 376736, 381028, 285778, 152990, 122410, 97946, \ 48976, 45946, 22976, 22744, 19916, 17716]) == True) test(son_sociables([28158165, 29902635, 30853845, 29971755]) == True)
from modulo_test import test def es_narcisista(n): es_narcista = True comparar = n cifra = len(str(n)) suma_potencia = 0 while es_narcista and n != 0: suma_potencia = suma_potencia + (n % 10)**cifra n = n // 10 if suma_potencia != comparar: es_narcista = False return es_narcista # –- Programa principal –- # Ejecutar el test sólo al ejecutar el fichero (y no al importarlo) if __name__ == '__main__': # Código para ejecutar la función con los datos de prueba # ¡¡SE PUEDE COMENTAR LÍNEAS PERO NO MODIFICARLAS!! test(es_narcisista(1) == True) test(es_narcisista(153) == True) test(es_narcisista(154) == False) test(es_narcisista(406) == False) test(es_narcisista(407) == True) test(es_narcisista(8208) == True) test(es_narcisista(92727) == True) test(es_narcisista(548834) == True) test(es_narcisista(24678051) == True)
## resultado = 0 ## for caracter in cadena: ## if caracter == "G" or caracter == "C": ## contador = contador + 1 ## resultado = round(contador / len(cadena) * porcentaje,2) ## return resultado def contenido_GC(cadena): contador = 0 distinto = 0 resultado = 0 for caracter in cadena: if caracter == "G" or caracter == "C": contador = contador + 1 resultado = round(100 / len(cadena) * (len(cadena) - contador), 2) return resultado # –- Programa principal –- # Ejecutar el test sólo al ejecutar el fichero (y no al importarlo) if __name__ == '__main__': # Código para ejecutar la función con los datos de prueba # ¡¡SE PUEDE COMENTAR LÍNEAS PERO NO MODIFICARLAS!! test(contenido_GC('GCGC') == 100.0) test(contenido_GC('CGCG') == 100.0) test(contenido_GC('GACGAC') == 66.67) test(contenido_GC('TACGTACGTAT') == 36.36) test(contenido_GC('CAGTACTACCTCAGACGT') == 50.0) test(contenido_GC('GATCGATCGATGCTAGCTAGCGCATC') == 53.85)