Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
作业是“我们为您提供一个值 N。计算 N!并仅输出最终结果。我一生都无法弄清楚这一点,我也不明白为什么我的代码至少不会运行。
# Get N from the command line import sys N = int(sys.argv[1]) def factorial(N): num = 1 while N >= 1: num = num * N N = N - 1 print(N)
首先,修复代码的格式.. 它看起来不对..
您的代码运行良好。但是您打印错误的数字作为答案。阶乘存储在num. 所以尝试打印num而不是N
num
N