# initialize a total variable to 0 before the loop
for numerator in range(1, 31, 1):
denominator = (31 - numerator)
quotient = numerator / denominator
print(quotient)
# update the total inside the loop (add the quotient to the total)
# print the total when the loop is complete
你可能还没有意识到答案。在
你快到了,我给你一些提示。在
如果您想看到一个更具Python(idomatic)的解决方案,请参阅zhangxaochen的答案。;)
为了提高效率:
如果必须在循环中显式地执行此操作,请参见@Bill's hints;)
相关问题 更多 >
编程相关推荐