Olá pessoal, hoje vamos realizar a implementação do fatorial em Python, estarei utilizando a IDE PyCharm.
O fatorial é uma sequencia de multiplicações de números inteiros positivo em ordem, não nulo e sem repetições .
Por exemplo:
3! = 1 x 2 x 3 = 6
4! = 1 x 2 x 3 x 4 = 24
5! = 1 x 2 x 3 x 4 x 5 = 120
Com as informações de como o fatorial funciona, abra sua IDE e vamos criar um script.
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
valor = int(input('Entre com um número para saber o fatorial:')) | |
fatorial = 1 | |
while (valor > 1): | |
fatorial = fatorial * valor | |
valor = valor - 1 | |
print('O fatorial é {}.'.format(fatorial)) |
O resultado após executar o script.