擅长:python、mysql、java
<p>如果您的代码是您在那里输入的,那么返回语句缩进太多,这就很容易了</p>
<pre><code>def calculateValues(loanAmt, numYears):
myAnswer = []
for monthlyRate in range (4, 9):
monthlyRate = monthlyRate / 100
monthlyPayment = loanAmt * monthlyRate / (1 - math.pow(1 / (1 + monthlyRate), numYears * 12))
totalPayment = monthlyPayment * numYears * 12
thisRound = (monthlyRate, monthlyPayment, totalPayment)
myAnswer.append(thisRound)
return myAnswer
</code></pre>
<p>在第一次迭代后返回的代码应该与上面的代码类似</p>
<p>我在这里只是猜测,如果您想要每个迭代的结果,您需要将它们保存在某个容器中。我个人会把它们保存在字典里,但在你的目标更加明确之前,我还没有准备好</p>
<p>在您感到更舒服之前,您应该考虑的一件事是向函数中添加一些print语句,这样您就可以在每次迭代期间看到值是什么</p>
<pre><code> def testFunction(somevalue):
for x in range(0, somevalue):
print 'hello'
return x
y = testFunction(2)
hello
hello
>>>y
1
</code></pre>