This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center。
我试着创建一个程序来检查每个数字是否等于其各个数字的阶乘之和。由于某种原因,它无法向列表中添加任何值,如果我要在每个实例之后打印summated变量,它将显示summated等于0。有人能帮忙吗?
import math
x = 2
y = 0
summed = 0
listed = []
while x < 10000000:
x += 1
summed = 0
xString = str(x)
xLength = len(xString)
while y < xLength:
summed += math.factorial(int(xString[y]))
y += 1
if (x == summed):
listed.append(x)
y = 0
summed = 0
listLength = len(listed)
while y < listLength:
summed += listed[y]
y += 1
print(listed)
print(summed)
最佳答案
你需要在while循环中设置y = 0
10-06 01:55