Re: Function to take the minimum of 3 numbers

2016-10-10 Thread Steve D'Aprano
On Mon, 10 Oct 2016 10:56 am, Ian Kelly wrote: > On Oct 9, 2016 2:57 PM, alleged: > The Pythonic way > > if b >= a <= c: > ... I doubt that would be considered Pythonic by many people. Chained comparisons are Pythonic, but not legal but weird combinations like `a

Re: Function to take the minimum of 3 numbers

2016-10-09 Thread Chris Angelico
On Mon, Oct 10, 2016 at 11:38 AM, Matt Wheeler wrote: > On Mon, 10 Oct 2016, 00:56 Ian Kelly, wrote: > >> On Oct 9, 2016 2:57 PM, wrote: >> The Pythonic way >> >> if b >= a <= c: >> ... >> >> >> Better: >> >> if a <= b <= c:

Re: Function to take the minimum of 3 numbers

2016-10-09 Thread Matt Wheeler
On Mon, 10 Oct 2016, 00:56 Ian Kelly, wrote: > On Oct 9, 2016 2:57 PM, wrote: > The Pythonic way > > if b >= a <= c: > ... > > > Better: > > if a <= b <= c: > ... > That's not equivalent. Consider `a, b, c = 1, 7, 4` > Using consistent

Re: Function to take the minimum of 3 numbers

2016-10-09 Thread Ian Kelly
On Oct 9, 2016 2:57 PM, wrote: On Sunday, October 9, 2016 at 2:41:41 PM UTC+1, BartC wrote: > def min3(a,b,c): > if a<=b and a<=c: > return a > elif b<=a and b<=c: > return b > else: > return c The Pythonic way if b >= a <= c:

Re: Function to take the minimum of 3 numbers

2016-10-09 Thread Larry Hudson via Python-list
On 10/09/2016 05:01 AM, Cai Gengyang wrote: def min3(a, b, c): min3 = a if b < min3: min3 = b if c < min3: min3 = c if b < c: min3 = b return min3 print(min3(4, 7, 5)) 4 This is NOT a recommendation here, just a different way of looking

Re: Function to take the minimum of 3 numbers

2016-10-09 Thread breamoreboy
On Sunday, October 9, 2016 at 2:41:41 PM UTC+1, BartC wrote: > On 09/10/2016 13:01, Cai Gengyang wrote: > > I'm moving on to chapter 9 > > (http://programarcadegames.com/index.php?lang=en=lab_functions) of > > programarcadegames for the time being and going back to chapter 8 later > > (its just

Re: Function to take the minimum of 3 numbers

2016-10-09 Thread Chris Angelico
On Mon, Oct 10, 2016 at 12:41 AM, BartC wrote: > The exercise says you must use an if/elif chain. The first thing that comes > to mind is: > > def min3(a,b,c): > if a<=b and a<=c: > return a > elif b<=a and b<=c: > return b > else: > return c >

Re: Function to take the minimum of 3 numbers

2016-10-09 Thread BartC
On 09/10/2016 13:01, Cai Gengyang wrote: I'm moving on to chapter 9 (http://programarcadegames.com/index.php?lang=en=lab_functions) of programarcadegames for the time being and going back to chapter 8 later (its just fucking frustrating and doesn't seem to work for the time being and I have a

Re: Function to take the minimum of 3 numbers

2016-10-09 Thread Ben Bacarisse
Cai Gengyang writes: > I'm moving on to chapter 9 > (http://programarcadegames.com/index.php?lang=en=lab_functions) > of programarcadegames for the time being and going back to chapter 8 > later (its just fucking frustrating and doesn't seem to work for the > time being

Function to take the minimum of 3 numbers

2016-10-09 Thread Cai Gengyang
I'm moving on to chapter 9 (http://programarcadegames.com/index.php?lang=en=lab_functions) of programarcadegames for the time being and going back to chapter 8 later (its just fucking frustrating and doesn't seem to work for the time being and I have a very bad temper). At least for chapter