I made a function to find the volume of a sphere:
function volume_sphere(r)
(4/3)(round(π, sigdigits=6))(r)^3
end
julia> println(volume_sphere(5))
I got this error message:
ERROR: MethodError: objects of type Float64 are not callable
Stacktrace:
[1] volume_sphere(::Int64) at C:\Users\Practice.jl:27
[2] top-level scope at none:0
Where is the issue coming from?
This problem is explained in detail here.
In short you are not allowed to omit *
in juxtaposition of two parenthesized expressions, nor when placing a variable before a parenthesized expression. Therefore this is a valid code:
4/3*round(π, sigdigits=6)*r^3
But you could write e.g. 2r+3(r^2+1)r
and it would be a valid line of code.
function volume_sphere(r)
(4/3)*(round(π, sigdigits=6))*(r^3)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With