avkLab

Factorielle

Jun 12th, 2022
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. #----------------------------------------------------------------------------
  4. # Created by  : Alain Van Kerckhoven
  5. # Created Date: 6 mars 2017
  6. # Licence     : GPL
  7. # Version     : 1.0
  8. # ---------------------------------------------------------------------------
  9. """
  10. calcule la factorielle d'un nombre (méthode récursive)
  11. """
  12. # ---------------------------------------------------------------------------
  13.  
  14. def fact(x):
  15.     if x < 2:
  16.         return 1
  17.     else:
  18.         return x * fact(x - 1)
  19.  
  20. nb = int(input("Introduisez un nombre : "))
  21. factorielle = fact(nb)
  22.  
  23. print(str(nb) + "! = " + str(factorielle))
Advertisement
Add Comment
Please, Sign In to add comment