首页 > 解决方案 > Julia:在 Pluto 中获取运行时输入

问题描述

我在 Pluto 笔记本中编写了以下代码

begin
    function newton_sqrt(x,error_margin)
        a=x/2
        e=abs(a-x/a)
        while e>error_margin
            a=(a+x/a)/2
            e=abs(a-x/a)        
        end 
        println(a)  
    end
    print("Input an integer: ")
    x = BigFloat(readline())
    newton_sqrt(x,0.0001)
end

我收到错误“ArgumentError:无法将“”解析为 BigFloat”。我无法从提示中获取输入。

任何帮助都会得到深深的承认。

标签: julia

解决方案


也许你应该使用这样的代码(我用 分隔冥王星细胞##):

using PlutoUI
##
@bind s TextField()
##
res = (s=="" ? "" : sqrt(BigFloat(s)))
##
md"The values of s is $s and the value of res is $res"

在此处输入图像描述


推荐阅读