Multiplication error in python
becky_lewis
bex.lewis at gmail.com
Tue Sep 27 13:43:00 EDT 2011
I tried running your code in ipython:
In [1]: l = [1,2,3,4,5]
In [2]: i = 0
In [3]: for a in l:
...: p = 2 * a
...: t = p + i
...: i = t
...:
In [4]:
In [4]: t
Out[4]: 30
The output from Python was 30, not 45. What Python version are you
running?
On Sep 27, 6:21 pm, sakthi <sakth... at gmail.com> 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
>
> 45
>
> Python gives an answer as 45. But i am getting 30 when i execute
> manually. Is there any different multiplication pattern in python?
> Thank yu.
More information about the Python-list
mailing list