Can anyone assist with this task?
<p>Write a while loop that exits when the sum of the squares 1^2 + 2^2 + 3^2 + â¦ exceeds an input m. Print the largest sum less than m and the number of terms in the sum.</p>

<pre><code>Example: If m = 18 then 
1^2 +2^2 + 3^2 = 1 + 4 + 9 = 14
1^2 +2^2 + 3^2 + 4^2 = 1 + 4 + 9 + 16 = 30
</code></pre>

<p>Therefore you should print out 3 and 14 for m = 18.</p>

<p>This is what I have so far, and I'm basically completely lost at this point:</p>

<pre><code>def sum_printer():
    y = input("Please enter a maximum number: ")
    y = int(y)
    for result in range(y):
        while result + result ** 2 &gt;= y:
            break
        else:
            print(str(result) + "^2 =", result ** 2, end=" ")


def sum_of_squares_result(m, n):
    return sum(result ** 2 for result in range(m, n))

sum_printer()
</code></pre>

<p>Can't figure out where I should go from here. Computing the sums of squares isn't a problem, neither is breaking the for loop when the sum of squares exceeds the user's input. I just can't figure out how to print 3 and 14 based off of the input.</p>

<p>What's wrong in your code is that you check <code>result + result**2</code> where <code>result</code> is each number in <code>range(y)</code>. You are basically checking if <code>1 + 1**2 &gt;= m</code>, <code>2 + 2**2 &gt;= m</code>, and so on. Here's how I would do it:</p>

<pre><code>def sum_printer():
    ceil = int(input("What is the maximum to not be exceeded? "))
    total = 0
    curr = 1

    while total + curr**2 &lt; ceil:
        total += curr**2
        curr += 1
    curr -= 1

    print(curr, total)
</code></pre>

python