User's input

Hi, I’m trying to generate a user’s input, so i wrote the nexts code lines:

function input(prompt)
print(prompt)
readline()
end
user_value = parse(Float64, input(“Age:”))

#Here end the user’s input and continue the program
set_value(pubinv, user_value)

But arise a problem, when I run the code lines “readline” keep going with next code lines. The error that throw is:

julia> function input(prompt)
print(prompt)
readline()
end
input (generic function with 2 methods)

julia> user_value = parse(Float64, input(“Age:”))
Age:4
ERROR: ArgumentError: cannot parse “set_value(pubinv, user_value)4” as Float64
Stacktrace:
[1] _parse_failure(::Type, ::String, ::Int64, ::Int64) at .\parse.jl:372 (repeats 2 times)
[2] #tryparse_internal#351 at .\parse.jl:368 [inlined]
[3] tryparse_internal at .\parse.jl:366 [inlined]
[4] #parse#352 at .\parse.jl:378 [inlined]
[5] parse(::Type{Float64}, ::String) at .\parse.jl:378
[6] top-level scope at REPL[83]:1

Someone can help me?

Hello, If you haven’t already, please read this post: PSA: make it easier to help you and follow it’s advice to make it easier for us to help you.

1 Like

It looks like somehow you typed in more than just 4 into the prompt. Can you show exactly what you types in response to readline In Julia?

This is that Julia makes when I response 4 (as input) and continues the next code line.
When I run for blocks no have a problem.

Thanks for the detailed illustration!

In the first one there is some strange indentation that makes me think your terminal is outputting some unusual whitespace. How are you running Julia? Are you on Windows, Mac, Linux?

I ask because I’ve had in the past some trouble (not with Julia) of direct input being different from copy and paste.

Is true it makes a strange indetation, but I believe it’s not a the problem because I run same codes lines on Visual Studio Code and arise same problem.
I’m on Windows and running Julia from copy and paste.