lundi 17 octobre 2016

Perfect Square function that doesn't return

I'm a beginner working with Python and I was given this task: write a function which returns the highest perfect square which is less or equal to its parameter (a positive integer).

def perfsq(n):

    x = 0
    xy = x * x
    if n >= 0:
        while xy < 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)))

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.

Aucun commentaire:

Enregistrer un commentaire