“Finden Sie die Fakultät einer bestimmten Ganzzahl in Python” Code-Antworten

Python Berechnen Sie die Fakultät

def factorial(n):
    fact = 1
    for num in range(2, n + 1):
        fact = fact * num
    return(fact)
Obedient Ox

Finden Sie die Fakultät einer bestimmten Ganzzahl in Python

import math
num = 5
print("The factorial of 5 is : ", end="")
print(math.factorial(num))

# output - The factorial of 5 is : 120

# The factorial of a number is the function that multiplies the number by every natural number below it
# e.g. - 1 * 2 * 3 * 4 * 5 = 120
Rajitha Amarasinghe

Schnelle Möglichkeit, den Faktor einer Zahl Python zu finden

def factors(x):
  listOfFactors = []
  for i in range(1, int(x ** 0.5)):   
    # Use a loop from 1 to the square root of x for more speed.
    if x % i == 0:
      listOfFactors.append(x)
      listOfFactors.append(i)
    # May repeat some numbers. Further code would be needed to fix that.
    print(i)
Inexpensive Impala

Ähnliche Antworten wie “Finden Sie die Fakultät einer bestimmten Ganzzahl in Python”

Fragen ähnlich wie “Finden Sie die Fakultät einer bestimmten Ganzzahl in Python”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen