本文介绍了为什么我的代码不返回任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前对编程和尝试学习 Python 还很陌生.我有这个代码,但我不明白为什么我没有得到返回值:(
fairly new to programming and trying to learn Python at the moment. I have this code and I don't understand why I don't get a return value :(
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
的地方.
You have to explicitly use the return
keyword. Probably where you currently have print c
.
f
需要在while循环后返回ba
.
f
needs to return ba
after the while loop.
这篇关于为什么我的代码不返回任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!