<blockquote>
<p>Write a program to show the sum of <code>(1**2) + (2**2) - (3**2) + (4**2)-,...,+(n**2)</code> program code in python using "for" and "While" loop.</p>
</blockquote>
<p>虽然我只为如下代码所示的<code>+</code>迭代编写,但是<code>+,-,+,-</code>迭代非常困难。这是我的<code>+</code>迭代代码:</p>
<pre><code>nstart = 1
nend = 4
count = 0
Sum = 0
for i in range(nstart,nend+1):
count+=1
d = i**2
Sum = Sum + d
print(count,'**2 = ', d )
print('Sum = ', Sum)
#This program print same as [(1**2,+ 2**2,+ 3**2= 9,+,,,,+n**2 and sum of them)]
</code></pre>