Multiplication error in python

Tim Roberts timr at
Wed Sep 28 02:28:32 EDT 2011

sakthi <sakthi92 at> wrote:

>In the following code,
>>>> l=[1,2,3,4,5]
>>>> i=0
>>>> for a in l:
>...     p=2*a
>...     t=p+i
>...     i=t
>>>> t
>Python gives an answer as 45. But i am getting 30 when i execute
>manually. Is there any different multiplication pattern in python?

My guess is that you actually typed
instead of

That produces 45.
Tim Roberts, timr at
Providenza & Boekelheide, Inc.

More information about the Python-list mailing list