Re: Multiplication error in python

2011-09-28 Thread Chris Angelico
On Wed, Sep 28, 2011 at 4:28 PM, Tim Roberts 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 -- http://mail.python.org/mailman/listin

Re: Multiplication error in python

2011-09-27 Thread Tim Roberts
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? My guess is that y

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 wrote: >> On Tue, Sep 27, 2011 at 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 >> >>> Py

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

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(

Re: Multiplication error in python

2011-09-27 Thread sakthi
On Sep 27, 1:43 pm, Chris Rebert wrote: > On Tue, Sep 27, 2011 at 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

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 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, sakth

Re: Multiplication error in python

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

Re: Multiplication error in python

2011-09-27 Thread Chris Rebert
On Tue, Sep 27, 2011 at 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 multiplicati

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. -- http://mail.python.org/mailman/lis