Julia: Taking Runtime Input in Pluto

Viewed 418

I have written following code in Pluto notebook

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

I am getting an error "ArgumentError: cannot parse "" as BigFloat". I am unable to take input from the Prompt.

Any help is deeply acknowledged.

1 Answers

Perhaps you should use code such as this one (I am separating Pluto cells by ##):

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

enter image description here

Related