Re: Multiplication error in python

2011-09-28 Thread Tim Roberts
sakthi sakth...@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? My guess is that you

Re: Multiplication error in python

2011-09-28 Thread Chris Angelico
On Wed, Sep 28, 2011 at 4:28 PM, Tim Roberts t...@probo.com wrote: My guess is that you actually typed    p=3*a instead of    p=2*a That produces 45. Or alternatively, that you used an interactive Python environment and didn't clear i between runs. ChrisA --

Multiplication error in python

2011-09-27 Thread sakthi
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. --

Re: Multiplication error in python

2011-09-27 Thread Chris Rebert
On Tue, Sep 27, 2011 at 10:21 AM, sakthi sakth...@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

Re: Multiplication error in python

2011-09-27 Thread nn
On Sep 27, 1:21 pm, sakthi sakth...@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

Re: Multiplication error in python

2011-09-27 Thread becky_lewis
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,

Re: Multiplication error in python

2011-09-27 Thread Gary Herron
On 09/27/2011 10:21 AM, sakthi 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. I think

Re: Multiplication error in python

2011-09-27 Thread sakthi
On Sep 27, 1:43 pm, Chris Rebert c...@rebertia.com wrote: On Tue, Sep 27, 2011 at 10:21 AM, sakthi sakth...@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

Re: Multiplication error in python

2011-09-27 Thread Alysson Bruno (WebSite)
In my python 3.2, no problem: l=[1,2,3,4,5] i=0 for a in l: ... p=2*a ... t=p+i ... i=t ... print(p={}, t={}, i={}.format(p,t,i)) ... p=2, t=2, i=2 p=4, t=6, i=6 p=6, t=12, i=12 p=8, t=20, i=20 p=10, t=30, i=30 t 30 paz e amor (love and peace), Alysson Bruno Palmas(TO) Brasil

Re: Multiplication error in python

2011-09-27 Thread becky_lewis
I think you may be doing something wrong. If I run: l = [1, 2, 3, 4, 5] i = 0 for a in l: ...i += 2 * a ... i 30 The result is 30 as expected. Nowhere near the 155 that you are getting. :/ Again, could you state which version of python are you using (and what OS) so that we

Re: Multiplication error in python

2011-09-27 Thread Tim Daneliuk
On 9/27/2011 12:50 PM, sakthi said this: On Sep 27, 1:43 pm, Chris Rebert c...@rebertia.com wrote: On Tue, Sep 27, 2011 at 10:21 AM, sakthi sakth...@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