I am getting error while running simple code

I have started to learn Julia. And I made a simple program using the function to find the area of the square. The code is below

# Given the length of square
function areaOfsquare()
    global s= input("Enter the length of side: ")
    a = s*s
    print("\n Area of square is $a")


UndefVarError: input not defined

[1] areaOfsquare()
@ Main .\In[12]:3
[2] top-level scope
@ In[12]:8
[3] eval
@ .\boot.jl:373 [inlined]
[4] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base .\loading.jl:1196

I tried global before the variable s but still getting the same error.

Hi! I don’t think there’s an input() function. (Perhaps Python has one?)

Something like this might work:

function areaOfsquare()
    print("Enter the length of side: \n")
    s = parse(Float64, readline())
    a = s * s
    print("\n Area of square is $a")

Thank you so much for your reply. It works.

1 Like