示例#1
0
def euler2(n):
    i = 0
    e = 0
    p = 1 / fatorial(2 * i + 1)
    while p >= n:
        e = e + p
        i += 1
        p = 1 / fatorial(2 * i + 1)
    return e
示例#2
0
def euler3(n):
    i = 0
    e = 0
    p = 1 / fatorial(2 * i + 1)
    d = 0
    while abs(p - d) > n:
        e = e + p
        d = p
        i += 1
        p = 1 / fatorial(2 * i + 1)
    return e
示例#3
0
def test_fatorial_quatro():
    assert fatorial(4) == 24
示例#4
0
 def test_fatorial_21_19(self):
     self.assertEqual(42, fatorial(21, 19))
示例#5
0
def test_fatorial_zero():
    assert fatorial(0) == 1
示例#6
0
 def test_fatorial_4_1(self):
     self.assertEqual(24, fatorial(4, 1))
示例#7
0
	def test_deveria_calcular_o_fatorial_de_5_corretamente(self):
		self.assertEqual(fatorial(5),120)
示例#8
0
def test_fatorial3():
    assert fatorial(3) == 6
示例#9
0
 def test_fatorial_10_3(self):
     self.assertEqual(280, fatorial(10, 3))
示例#10
0
def test_fatorial7():
    assert fatorial.fatorial(7) == 5040
示例#11
0
def test_fatorial1():
    assert fatorial.fatorial(1) == 1
示例#12
0
def test_fatorial4():
    assert fatorial.fatorial(4) == 24
示例#13
0
def test_fatorial6():
    assert fatorial.fatorial(6) == 720
示例#14
0
def test_fatorial3():
    assert fatorial(10) == 3628800
示例#15
0
 def test_fatorial_2_1(self):
     self.assertEqual(2, fatorial(2, 1))
示例#16
0
 def test_fatorial_1_1(self):
     self.assertEqual(1, fatorial(1, 1))
示例#17
0
def testa_fatorial(entrada, esperado):
    assert fatorial.fatorial(entrada) == esperado
示例#18
0
def test_fa5():
    assert fatorial(-1) == 1
示例#19
0
def test_fatorial_negativo():
    assert fatorial(-3) == 0
示例#20
0
def test_fa3():
    assert fatorial(4) == 24
示例#21
0
 def test_fatorial_3_1(self):
     self.assertEqual(6, fatorial(3, 1))
示例#22
0
e^x = 1 + x + x²/2! + x³/3! ... x^n/n!

Assim, qualquer aproximação será iniciada com o valor igual a 1. 
"""

i = 1  #equivale ao numero de iteração ou n em x^n/n!
x = 0.5  #parametro para aproximação
aproximacao = 1
calculo_anterior = aproximacao
#Reserva o calculo da iteração anterior para calcular o erro
"""
 Os resultados poderiam ser implementados em um array para armazenar o resultado anterior,
porém foi escolhido fazer por uma variável
"""

# Série de Maclaurin

while (ea > tol):

    Mac = (x**i) / fatorial.fatorial(i)
    aproximacao += Mac
    i += 1

    ea = Erros.erro_aproximado(aproximacao, calculo_anterior)

    calculo_anterior = aproximacao

print(f"O resultado aproximado é {aproximacao}")
print(f"O erro aproximado é de {ea}")
print(f"Foram necessárias {i} iterações")
示例#23
0
 def test_fatorial_1_1(self):
     self.assertEqual(1, fatorial(1, 1))
示例#24
0
	def test_deveria_calcular_o_fatorial_de_10_corretamente(self):
		self.assertEqual(fatorial(10),3628800)
def coef_binominal(n, k): # Definição de função que calcula o coeficiente binominal
    
    coef = fatorial.fatorial(n) / (fatorial.fatorial(k) * (fatorial.fatorial(n-k))) # Função fatorial chamada três vezes
    coef = int(coef)

    return coef
示例#26
0
from tictactoe import printBoard
from fatorial import fatorial

theBoard = {
    'top-L': ' ',
    'top-M': ' ',
    'top-R': ' ',
    'mid-L': ' ',
    'mid-M': ' ',
    'mid-R': ' ',
    'low-L': ' ',
    'low-M': ' ',
    'low-R': ' '
}

printBoard(theBoard)

theBoard[0, 0] = 'x'

printBoard(theBoard)

print(fatorial(5))
示例#27
0
	def test_deveria_calcular_o_fatorial_de_6_corretamente(self):
		self.assertEqual(fatorial(6),720)
示例#28
0
 def test_fatorial_10_3(self):
     self.assertEqual(280, fatorial(10, 3))
示例#29
0
	def test_deveria_calcular_o_fatorial_de_2_corretamente(self):
		self.assertEqual(fatorial(2),2)
示例#30
0
def euler1(n):
    e = 0
    for x in range(0, n):
        e = e + 1 / fatorial(2 * x + 1)
    return e
示例#31
0
def test_fatorial_dois():
    assert fatorial(2) == 2
示例#32
0
	def test_fatorial_1(self):
		self.assertEqual(fatorial(1), 1)
示例#33
0
def test_fatorial_um():
    assert fatorial(1) == 1
示例#34
0
	def test_fatorial_2(self):
		self.assertEqual(fatorial(2), 2)
示例#35
0
def test_fatorial_tres():
    assert fatorial(3) == 6
示例#36
0
	def test_fatorial_3(self):
		self.assertEqual(fatorial(3), 6)
示例#37
0
from adicao import adicao
from fatorial import fatorial
from multiplicacao import multiplicacao

numero1 = 10
numero2 = 20

opcao = 1

resultado = 0

if opcao == 1:
    resultado = adicao(numero1, numero2)
elif opcao == 2:
    resultado = fatorial(numero1, numero2)
elif opcao == 3:
    resultado = multiplicacao(numero1, numero2)

print('Resultado:', resultado)
示例#38
0
	def test_fatorial_5(self):
		self.assertEqual(fatorial(5), 120)
示例#39
0
def test_fatorial2():
    assert fatorial(2) == 2
示例#40
0
	def test_fatorial_minus_1(self):
		with self.assertRaises(NotNaturalNumberError):
			fatorial(-1)
示例#41
0
def test_fatorial5():
    assert fatorial(5) == 120
示例#42
0
	def test_fatorial_negative(self):
		with self.assertRaises(NotNaturalNumberError):
			fatorial(randrange(-100,0))
示例#43
0
 def test_fatorial_4_1(self):
     self.assertEqual(24, fatorial(4, 1))
示例#44
0
	def test_fatorial_float(self):
		with self.assertRaises(NotNaturalNumberError):
			fatorial(randrange(1,100) / 10.0)
示例#45
0
 def test_fatorial_21_19(self):
     self.assertEqual(42, fatorial(21, 19))
示例#46
0
	def test_fatorial_0(self):
		self.assertEqual(fatorial(0), 1)
示例#47
0
 def test_fatorial_2_1(self):
     self.assertEqual(2, fatorial(2, 1))
示例#48
0
 def test_fatorial_3_1(self):
     self.assertEqual(6, fatorial(3, 1))