题解 | #求解立方根#

求解立方根

https://www.nowcoder.com/practice/caf35ae421194a1090c22fe223357dca

src = float(input().strip())

croot = 0
eps = 1e-6
left, right = -3, 3
while abs(croot ** 3 - src) >= eps:
    c3 = croot ** 3
    if c3 < src:
        left = croot
        croot = (right + croot) / 2
    else:
        right = croot
        croot = (croot + left) / 2
print(f"{croot:.1f}")

全部评论

相关推荐

双非阴暗爬行:我来看看笑死我了,这名字取得好想笑(没有不好的意思)
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务