查找数字列表的阶乘

Sak*_*ain 4 python math for-loop factorial

我有一组数字:

list = {1, 2, 3, 4, 5}
Run Code Online (Sandbox Code Playgroud)

我希望创建一个函数来计算集合中每个数字的阶乘并打印它.

input_set = {1, 2, 3, 4, 5}
fact = 1
for item in input_set:
    for number in range(1,item+1):
        fact = fact * number
    print ("Factorial of", item, "is", fact)
Run Code Online (Sandbox Code Playgroud)

我得到的输出是:

Factorial of 1 is 1
Factorial of 2 is 2
Factorial of 3 is 12
Factorial of 4 is 288
Factorial of 5 is 34560
Run Code Online (Sandbox Code Playgroud)

这显然是错的.我真的想知道我的代码有什么问题以及如何修复它.

注意:我不希望将此math.factorial函数用于此代码.

Van*_*eer 6

fact=1在里面设置循环.

input_set = {1, 2, 3, 4, 5}
for item in input_set:
    fact = 1
    for number in range(1,item+1):
        fact = fact * number
        print ("Factorial of", input, "is", fact)
Run Code Online (Sandbox Code Playgroud)