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>Like Patrick Haugh says, try examining when the while loop exits. It can be helpful to put print() statements throughout your method to figure out how your method executes. In order to figure out when your loop exits, look at the exit condition of your while loop: xy &lt; n. </p>

<p>Remember, a variable isn't updated until you update it.</p>

<pre><code>def perfsq(n):
    x = 0
    xy = x * x
    print("xy: {}".format(xy))
    if n &gt;= 0:
        while xy &lt; n:
            x += 1
            print("xy in loop: {}".format(xy))

        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>

python loops if-statement