Advertisement
teslariu

factorial

Sep 10th, 2021
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. """Hacer un script con funciones que calcule el factorial de un nro
  5. Ejemplo
  6.     7! = 7 x 6 x 5 x 4 x 3 x 2 x 1
  7.     5! = 5 x 4 x 3 x 2 x 1
  8. """
  9.  
  10. def factorial(n):
  11.     fact = n
  12.     for i in range(n-1, 0, -1):
  13.         fact = fact * i
  14.     return fact
  15.    
  16.  
  17. print("Cálculo del factorial de un número entero")
  18. numero = int(input("Ingrese un número entero: "))
  19.  
  20. fact = factorial(numero)
  21. print(fact)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement