Why is math.sqrt(r**2 - (x-h)**2) + k returning a ValueError: math domain error
<pre><code>def drawCircle(h, k, r):
    #(x-h)^2 + (y-k)^2 = r^2
    for x in range(screen.Width):
        y = (math.sqrt(r**2 - (x-h)**2) + k)
        if y % 1 == 0:
            screen.Set(x, int(y), "X")

drawCircle(0, 0, 5)
</code></pre>

<p>screen is a simple console renderer library that I wrote that positions items in a 2D array with the most top-left corner being (0,0) </p>

<p>It is my guess that the result in parens that you are <code>sqrt</code>ing ends up being negative at some point. If and when it does, the error you are seeing will be raised when you try to take the square root of that number. </p>

<p>To confirm this, try saving <code>r**2 - (x-h)**2</code> to a variable and printing it before taking the <code>sqrt</code>. </p>

python math