osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Code for addition


On 2017-08-05, Ode Idoko via Python-list <python-list at python.org>
wrote:
> Can anyone help with the python code that can add 101, 102,
> 103...2033 please? As I said before, I'm new to python and need
> assistance in this regard. Thanks for always assisting. 

>>> (2033 - 101 + 1) * (101 + 2033) / 2

You could also calculate it with a combination of sum and range
builtins, as others have hinted, and if it's homework that's
probably a good idea.

-- 
Neil Cerutti