def fvals_sqrt(x):
"""
Return f(x) and f'(x) for applying Newton to find a square root.
"""
f = x**2 - 4.
fp = 2.*x
return f, fp
def solve(fvals_sqrt, x0, debug_solve=True):
"""
Solves the sqrt function, using newtons methon.
"""
fvals_sqrt(x0)
x0 = x0 + (f/fp)
print x0
当我尝试调用函数解决,蟒蛇回报Python变量范围:与函数作为参数
NameError: global name 'f' is not defined
显然,这是一个范围的问题,但我怎么能使用f内我的解决功能?