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,(n + 1)) - >'范围(1,(n + 1)):' – Ben
OMG。非常感谢你。 – wraith46