Perfect Square function that doesn't return
<p>I'm a beginner working with Python and I was given this task: <em>write a function which returns the highest perfect square which is less or equal to its parameter (a positive integer).</em></p>

<pre><code>def perfsq(n):

    x = 0
    xy = x * x
    if n &gt;= 0:
        while xy &lt; n:
            x += 1

        if xy != n:
            print (("%s is not a perfect square.") % (n))
            x -= 1
            print (("%s is the next highest perfect square.") % (xy))
        else:
            return(print(("%s is a perfect square of %s.") % (n, x)))
</code></pre>

<p>When I run the code to execute the function it doesn't output anything. I'll admit, I'm struggling and if you could give me some advice on how to fix this, I would be grateful.</p>

<p>your loop condition which is</p>

<pre><code>while xy &lt; n:
</code></pre>

<p>this will be true always as xy is always 0 and n is always greater then zero if you will call the function with n = 0, it will print <code>0 is a perfect square of 0.</code> and will return None.</p>

<pre><code>for n &gt; 0
</code></pre>

<p>why it is always <code>true</code> in the case of <code>xy &lt; n</code> because you have assigned xy <code>0</code> and never modified it to anyother value when a loop runs it check the condition and it will always get <code>True</code> </p>

python loops if-statement