I am new to Julia, could someone help me to check the code?

It is a square root language,

I recommend you follow the suggestion of this PSA and use triple backticks to indent and make your code easier to read.

1 Like

Please quote your code in backticks

```
like this
```

You have r = 9 and y = 0, then you are asserting that x == y^2. This is the error you get (which you should also post).

Your code doesn’t work because you have told it to error when there is a false condition! 9 != 0

1 Like

The error is not x == y^2 as the code is x == y^2 + r (which is correct), the problem is in 0 <= r< 2*y + 1 in the second assert, for (r, y) = (8, 1) it evaluates to false as 8 < (2*1 + 1) is not true.

1 Like

I strongly suggest starting with functions (and/or scripts that don’t include let, preferably in jupyter). If you are an advanced programmers you will understand let quickly, but otherwise you are better off starting without it… it is relatively infrequent in most code.

3 Likes

Please don’t post the same question multiple times, this seems to be the same issue as in this thread.

Also is this a homework problem? I ask as someone posted the same question on StackOverflow yesterday and removed it after I asked whether it was a homework problem. It’s fine to ask for help with homework here, but you might want to have a look at our informal homework policy.

1 Like

Such questions arise frequently, which could easily be answered by reading the documentation. I would not dare to ask something like that