Created
May 19, 2011 01:53
-
-
Save tarsisazevedo/980011 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from unittest import TestCase | |
import math | |
class FatorialDeN(TestCase): | |
def test_soma_do_resultado_do_fatorial_de_10(self): | |
self.assertEquals(27, soma_do_fatorial_de_n(n=10)) | |
def test_soma_do_resultado_do_fatorial_de_100(self): | |
self.assertEquals(648, soma_do_fatorial_de_n(n=100)) | |
def soma_do_fatorial_de_n(n): | |
fatorial_n = math.factorial(n) | |
resultado = 0 | |
for numero in str(fatorial_n): | |
resultado += int(numero) | |
return resultado |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Douglas,
A biblioteca padrão já possui a função math.factorial. Com certeza a performance dela já foi otimizada, então não vejo válido usar uma função lambda neste caso. Isso sim eu acho que reduz a legibilidade :-)