Re: Multiplication

2024-04-01 Thread dn via Python-list
The April Fools joke was on those of us who never received/have yet to receive @Stefan's OP. On 2/04/24 08:02, Avi Gross via Python-list wrote: Is this a April 1 post for fools. Multiplication with an asterisk symbol is built into python. The same symbol used in other contexts has other con

Re: Multiplication

2024-04-01 Thread Avi Gross via Python-list
Is this a April 1 post for fools. Multiplication with an asterisk symbol is built into python. The same symbol used in other contexts has other contexts has an assortment of largely unrelated meanings such as meaning everything when used to import. On Mon, Apr 1, 2024, 1:27 PM Piergiorgio Sarto

Re: Multiplication

2024-04-01 Thread D'Arcy Cain via Python-list
On 2024-04-01 12:35, Joel Goldstick via Python-list wrote: On Mon, Apr 1, 2024 at 1:26 PM Piergiorgio Sartor via Python-list ^^^ from math import * a = 2 b = 3 print( a * b ) I guess the operator "*" can be imported from any module... :-) No import is necessary. Of cour

Re: Multiplication

2024-04-01 Thread Joel Goldstick via Python-list
On Mon, Apr 1, 2024 at 1:26 PM Piergiorgio Sartor via Python-list wrote: > > On 01/04/2024 10.40, Stefan Ram wrote: > > Q: How can I multiply two variables in Python? I tried: > > > > a = 2 > > b = 3 > > print( ab ) > > > > but it did not work. > > > > A: No, this cannot work. To mu

Re: Multiplication

2024-04-01 Thread Piergiorgio Sartor via Python-list
On 01/04/2024 10.40, Stefan Ram wrote: Q: How can I multiply two variables in Python? I tried: a = 2 b = 3 print( ab ) but it did not work. A: No, this cannot work. To multiply, you need the multiplication operator. You can import the multiplication operator from "mat

Re: Multiplication [was Re: Late-binding of function defaults]

2015-11-25 Thread Marko Rauhamaa
Steven D'Aprano : > But by this time, we had already learned in secondary school that you can > use any of the following to write multiplication: > > x × y Not where I lived. (Those x's would have been a nightmare for the teacher who had to mark people's test answers.) > x ⋅ y Yes. After all, i

Re: Multiplication [was Re: Late-binding of function defaults]

2015-11-25 Thread Laura Creighton
In a message of Thu, 26 Nov 2015 05:09:13 +1100, "Steven D'Aprano" writes: >On Thu, 26 Nov 2015 02:59 am, Laura Creighton wrote: > >> The great sticking point for the children I am teaching is >> '*' means multiplication. You can really see that some people >> have to make extensive mental modific

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

Re: multiplication of lists of strings

2008-03-08 Thread castironpi
On Mar 8, 12:04 pm, [EMAIL PROTECTED] wrote: > On Mar 5, 2:16 am, Bruno Desthuilliers > [EMAIL PROTECTED]> wrote: > > [EMAIL PROTECTED] a écrit : > > (snip) > > > > That reminds me:  Is there a generic 'relation' pattern/recipie, such > > > as finding a computer that's "paired" with multiple users

Re: multiplication of lists of strings

2008-03-08 Thread castironpi
On Mar 5, 2:16 am, Bruno Desthuilliers wrote: > [EMAIL PROTECTED] a écrit : > (snip) > > > That reminds me:  Is there a generic 'relation' pattern/recipie, such > > as finding a computer that's "paired" with multiple users, each of who > > are "paired" with multiple computers, without maintaining

Re: multiplication of lists of strings

2008-03-05 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : (snip) > > That reminds me: Is there a generic 'relation' pattern/recipie, such > as finding a computer that's "paired" with multiple users, each of who > are "paired" with multiple computers, without maintaining dual- > associativity? > Yes : use a relational databas

Re: multiplication of lists of strings

2008-03-04 Thread castironpi
On Mar 4, 9:46 pm, Jason Galyon <[EMAIL PROTECTED]> wrote: > Gabriel Genellina wrote: > > En Tue, 04 Mar 2008 23:50:49 -0200, Jason <[EMAIL PROTECTED]> escribió: > > >> How could I return a list or tuple of each unique combination of a given > >> set of lists (perhaps from a dict or a list).  This

Re: multiplication of lists of strings

2008-03-04 Thread Jason Galyon
Gabriel Genellina wrote: > En Tue, 04 Mar 2008 23:50:49 -0200, Jason <[EMAIL PROTECTED]> escribió: > >> How could I return a list or tuple of each unique combination of a given >> set of lists (perhaps from a dict or a list). This means the number of >> lists are not known nor is the length of ea

Re: multiplication of lists of strings

2008-03-04 Thread Gabriel Genellina
En Tue, 04 Mar 2008 23:50:49 -0200, Jason <[EMAIL PROTECTED]> escribió: > How could I return a list or tuple of each unique combination of a given > set of lists (perhaps from a dict or a list). This means the number of > lists are not known nor is the length of each. Use the Google interfase fo

Re: Multiplication optimization

2006-02-20 Thread Tim Roberts
"Paul McGuire" <[EMAIL PROTECTED]> wrote: > >Does Python's run-time do any optimization of multiplication >operations, like it does for boolean short-cutting? That is, for a >product a*b, is there any shortcutting of (potentially expensive) >multiplication operations as in: Integer multiplication

Re: Multiplication optimization

2006-02-20 Thread Peter Otten
Atanas Banov wrote: > Paul McGuire wrote: >> Does Python's run-time do any optimization of multiplication >> operations, like it does for boolean short-cutting? That is, for a >> product a*b, is there any shortcutting of (potentially expensive) >> multiplication operations > > no. and the reason

Re: Multiplication optimization

2006-02-19 Thread Atanas Banov
Paul McGuire wrote: > Does Python's run-time do any optimization of multiplication > operations, like it does for boolean short-cutting? That is, for a > product a*b, is there any shortcutting of (potentially expensive) > multiplication operations no. and the reason is very simple: to the extent

Re: Multiplication optimization

2006-02-18 Thread Jean-Paul Calderone
On 18 Feb 2006 16:48:38 -0800, Paul McGuire <[EMAIL PROTECTED]> wrote: >Does Python's run-time do any optimization of multiplication >operations, like it does for boolean short-cutting? Here's the beginning of int_mul from Objects/intobject.c: static PyObject * int_mul(PyObject *v, PyObje

Re: Multiplication optimization

2006-02-18 Thread Raymond Hettinger
[Paul McGuire] > Does Python's run-time do any optimization of multiplication > operations, like it does for boolean short-cutting? Usually, it is safest (and typically true) to assume that Python performs no optimizations. To go beyond making assumptions, it is easy to run a few timings: >>> fr

Re: Multiplication optimization

2006-02-18 Thread Steven D'Aprano
On Sat, 18 Feb 2006 16:48:38 -0800, Paul McGuire wrote: > Does Python's run-time do any optimization of multiplication > operations, like it does for boolean short-cutting? Do you know that these shortcuts are optimizations, or are you just assuming it takes less time to do the comparison than it