2017-03-03 104 views
0

我正在尝试使用for循环和累加器来计算的阶乘n。我遇到了范围命令及其两个参数 - 开始和结束的问题。我得到无效的语法错误。代码如下:使用两个参数计算n的阶乘使用范围

# factorial.py 
# Program to compute the factorial of a number 
# Illustrates for loop with an accumulator 

def main(): 

    n = int(input("Please enter a whole number: ")) 

    fact = 1 

    for factor in range(1, (n + 1)) 
     fact = fact * factor 

    print("The factorial of", n, "is", fact) 


main() 

问题在哪?

我正在使用Python 3.6。

+1

添加一个冒号。范围(1,(n + 1)) - >'范围(1,(n + 1)):' – Ben

+0

OMG。非常感谢你。 – wraith46

回答

0

你简单地在你的范围函数后面忘了:,因为它是一个for循环^。^

+0

确实。谢谢。 – wraith46