目前对编程还很陌生,正在尝试学习Python。我有这段代码,但我不明白为什么我没有得到返回值:(
balance = 3200
annualInterestRate = 0.2
monthlyInterestRate = (annualInterestRate/12 + 1)
def f(x):
m = 0
ba = balance
while m < 12:
ba = (ba - x)*monthlyInterestRate
m += 1
return ba
def bisection():
a = 0
b = balance
c = (a+b)/2
while a != b:
if f(c) == 0:
return c
elif f(c) < 0:
a = c
else:
b = c
c = (a+b)/2
return c
bisection()
你必须明确地使用return
关键词。可能是您目前所在的位置print c
.
f
需要返回ba
在 while 循环之后。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)