pythonize this!

Paul Rubin no.email at nospam.invalid
Tue Jun 15 14:41:03 EDT 2010


superpollo <utente at esempio.net> writes:
> goal (from e.c.m.): evaluate
> 1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three
> consecutive + must be followed by two - (^ meaning ** in this context)

print sum([-1,1,1,1,-1][i%5]*i**2 for i in xrange(1,2011))



More information about the Python-list mailing list