对于多个输入,这显示了奇怪的结果,例如:对于 2、4、5 ,它的输出显示为 24、24 。
T = int(raw_input())
L = []
for i in range(0,T):
num = int(raw_input())
L.append(num)
product = 1
k = 0
for item in L:
while k < item:
term = item - k
product = product * term
k = k + 1
print product
答案 0 :(得分:1)
您应该修复第一个for
循环的缩进。然后在主product
循环内初始化k
和for
,以便可以为每个输入数字重置它们。变量term
是多余的,因为您可以简单地将product
乘以k
:
T = int(raw_input())
L = []
for i in range(0,T):
num = int(raw_input())
L.append(num)
for item in L:
k = 1
product = 1
while k <= item:
product = product * k
k = k + 1
print product