1

The following script is supposed to compute the sum of integer squares from 0 to 4.

Mathematically, 0²+1²+2²+3²+4²=30, but the script prints 4 when run on Python 3.2! Why?

total = 0
for val in range(5):
    vаl = val * val
    tоtal = total + val

print(tоtal)
4

1 に答える 1

7
于 2012-12-27T15:28:35.143 に答える