<p>我正试图编写一个简短的代码,以计算出由于每日利息而达到银行给定本金所需的天数。在空闲状态下运行时,使用下面的代码不会产生任何错误,但计数器返回0。你知道我错过了什么吗?在</p>
<pre><code>def main():
# irrelevant code elided by msw, Bal, Int and Tar are numeric
counter = 0
for i in range(0):
if (Bal * Int) == Tar:
print '1'
else:
counter + 1
print counter
</code></pre>
<pre><code>In [5]: def test():
...: for i in range(0):
...: return '1'
...:
...:
In [6]: x = test()
In [7]: print x
------> print(x)
None
</code></pre>
<p>请参见返回值为“None”。
我不知道你想做什么。但最基本的错误是范围(x)函数的参数。范围(0)始终返回空列表。在</p>