2024-10-16 17:28:06 发布
网友
repeat1=0 while repeat1!=x1: fini=ord(dlist[repeat1]) repeat1=repeat1+1 print (fini) sum_of_all=sum(fini) print(sum_of_all)
我想把变量fini的数字相加。 python给了我一个错误:“int”不是iterable。你知道吗
你需要建立一个这些数字的列表。相反,您只是将每个数字分配给fini,而不使用前面的数字:
fini
values = [] while repeat1 != x1: fini = ord(dlist[repeat1]) values.append(fini) repeat1 = repeat1 + 1 sum_of_all = sum(values)
不过,您也可以对循环中的值求和:
sum_of_all = 0 while repeat1 != x1: fini = ord(dlist[repeat1]) sum_of_all += fini repeat1 = repeat1 + 1 print(sum_of_all)
你需要建立一个这些数字的列表。相反,您只是将每个数字分配给
fini
,而不使用前面的数字:不过,您也可以对循环中的值求和:
相关问题 更多 >
编程相关推荐