pythonize this!

Richard Brodie R.Brodie at rl.ac.uk
Wed Jun 16 08:41:26 EDT 2010


"Lie Ryan" <lie.1296 at gmail.com> wrote in message news:4c18ac33 at dnews.tpgi.com.au...

> Probably bending the rules a little bit:
>
>>>> sum(x**2 - 8*x - 20 for x in range(1, 2010, 5))
> 536926141

Or, letting Python do the algera for you:

>>> from sympy import var, sum
>>> dummy = var('j k')
>>> k = (5 * j) + 1
>>> t = (k)**2 + (k + 1)**2 + (k + 2)**2 - (k + 3)**2 - (k + 4)**2
>>> sum(t, (j, 0, 401))
536926141 





More information about the Python-list mailing list