【问题标题】:how is my square root program being interpreted我的平方根程序是如何被解释的
【发布时间】:2018-03-14 14:43:24
【问题描述】:

如何解释我的平方根程序,因为它似乎没有给我答案?

def square_root(f):
    g=f
    while g**2!=f:
        g = 1.5*(g+f/g)
    return g

【问题讨论】:

  • 请编辑您的问题以显示您提供的输入以及您得到的输出。
  • 看起来你忘记调用你定义的函数了。

标签: python python-2.7


【解决方案1】:

它不起作用,因为这部分 g = 1.5*(g+f/g) 是错误的

def square_root(f):
    g = f
    while g**2 > f:
        g = 0.5*(g+f/g)
    return g

看看我的功能: myfunction 你的: yourfunction

【讨论】:

    猜你喜欢
    • 2011-10-06
    • 1970-01-01
    • 1970-01-01
    • 2021-01-04
    • 1970-01-01
    • 2015-08-22
    • 2018-05-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多