Code for addition

Neil Cerutti neilc at norwich.edu
Mon Aug 7 16:39:28 EDT 2017


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




More information about the Python-list mailing list