factorial

Factorial calculation using Python

Factorial calculation using Python Question: I am new to Python and currently reading Python 3 for absolute beginner and face following problem. I would like to calculate factorial with procedure. request user to input an non negative number n then use for loop to calculate factorial and the code is like that: N = input(“Please …

Total answers: 6

Why is math.factorial much slower in Python 2.x than 3.x?

Why is math.factorial much slower in Python 2.x than 3.x? Question: I get the following results on my machine: Python 3.2.2 (default, Sep 4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)] on win 32 Type “help”, “copyright”, “credits” or “license” for more information. >>> import timeit >>> timeit.timeit(‘factorial(10000)’, ‘from math import factorial’, number=100) 1.9785256226699202 >>> …

Total answers: 1

recursive factorial function

recursive factorial function Question: How can I combine these two functions into one recursive function to have this result: factorial(6) 1! = 1 2! = 2 3! = 6 4! = 24 5! = 120 6! = 720 This is the current code for my factorial function: def factorial(n): if n < 1: # base …

Total answers: 15