我编写了一个小函数来检查两个值中哪个离零最近。我遇到的问题是在结尾的打印语句中:我希望它打印文本,然后再跟上它确定为最接近的值。
def closestcheck(ylow, yhigh, ylist, xlist):
ynew = (ylow + yhigh) / 2
#The following 2 prints are purely to check the calculations are correct
print(ynew)
print(ylow,yhigh)
if ynew > 0:
print('The closest value of theta is' % ylow)
else:
print('The closest value of theta is' % yhigh)
closestcheck(y0[-1],y0[-2],y0,x0)
它会打印文本但不会打印数字
6.13910823576e-07
-3.46867223283e-06 4.69649387998e-06
最接近theta的值是
这个特定的语法在其他情况下可以工作,但在这里不行,我不确定为什么。非常感谢您提供为什么它不能工作以及如何修复它的解释,谢谢!