Python math.factorial()- Methode
Beispiel
Finden Sie die Fakultät einer Zahl:
#Import math Library
import math
#Return factorial of a number
print(math.factorial(9))
print(math.factorial(6))
print(math.factorial(12))
Definition und Verwendung
Die math.factorial()
Methode gibt die Fakultät einer Zahl zurück.
Hinweis: Diese Methode akzeptiert nur positive ganze Zahlen.
Die Fakultät einer Zahl ist die Summe der Multiplikation aller ganzen Zahlen von unserer angegebenen Zahl bis 1. Zum Beispiel wäre die Fakultät von 6 6 x 5 x 4 x 3 x 2 x 1 = 720
Syntax
math.factorial(x)
Parameterwerte
Parameter | Description |
---|---|
x | Required. A positive integer. If the number is negative, or not an integer, it returns a ValueError. If the value is not a number, it returns a TypeError |
Technische Details
Rückgabewert: | Ein positiver int Wert |
---|---|
Python-Version: | 2.6 |