Anonymous

# help with python print operations/messages?

so I have the following algorithm I have created to calculate the sum of squares of n:

n=6

count=1

total=0

while count<=n:

total=total+count*count

count=count+1

I am wondering how to make my algorithm print the following:

"The sum of squares from 1 to 6 = 91"

But I would obviously want it to print the right statement depending on the input number, n. Can someone explain how to code this?

Update:

**IN PYTHON 2 PLEASE

### 3 Answers

Relevance

- husoskiLv 77 months agoFavorite Answer
That print call in brilliant_moves's answer *will* work in Python 2. (2.6 or later, but 2.7 has been the only supported Python 2 version for years.)

If you want something that *only* works with Python 2, then you can change that line to:

print "The sum of squares from 1 to", n, "=", total

Still have questions? Get your answers by asking now.