Re: [Tutor] how to unittest cli input

2015-10-14 Thread Alex Kleider
On 2015-10-14 12:27, Peter Otten wrote: Alex Kleider wrote: On 2015-10-13 14:44, Alex Kleider wrote: On 2015-10-13 12:11, Danny Yoo wrote: ## def make_ask(f, l, p): d = {'Enter your first name: ' : f, 'Enter your last name: ' : l, 'Your mobile p

tutor@python.org

2015-10-14 Thread Steven D'Aprano
On Wed, Oct 14, 2015 at 01:47:02PM -0700, ਨਿਹੰਗ ਪੰਜਾਬੀ wrote: > 'if (n & 1)' below works but I don't understand why/how. Kindly help. > > == > >>> def fn(n): > ... if (n & 1): > ... print "n is odd" > ... else: > ... print "n is even" & is the "bitwise AND"

tutor@python.org

2015-10-14 Thread Joel Goldstick
On Wed, Oct 14, 2015 at 7:39 PM, Laura Creighton wrote: > In a message of Wed, 14 Oct 2015 19:29:47 -0400, Joel Goldstick writes: > >& is a bitwise operator, so any odd number and 1 will be one (true), and > >any even number will be zero (false) > > You and Ben seem to have missed the problem in

tutor@python.org

2015-10-14 Thread Laura Creighton
In a message of Wed, 14 Oct 2015 19:29:47 -0400, Joel Goldstick writes: >& is a bitwise operator, so any odd number and 1 will be one (true), and >any even number will be zero (false) You and Ben seem to have missed the problem in the answer. I think that Ni needs to understand _how bitwise operat

tutor@python.org

2015-10-14 Thread Robert Nanney
To elaborate a little more this is comparing the 'one' bit. Any odd number will have the 'one' bit set. On Oct 14, 2015 6:30 PM, "Joel Goldstick" wrote: > On Wed, Oct 14, 2015 at 4:47 PM, ਨਿਹੰਗ ਪੰਜਾਬੀ wrote: > > > 'if (n & 1)' below works but I don't understand why/how. Kindly help. > > > > =

tutor@python.org

2015-10-14 Thread Alan Gauld
On 14/10/15 21:47, ਨਿਹੰਗ ਪੰਜਾਬੀ wrote: 'if (n & 1)' below works but I don't understand why/how. Kindly help. Do you understand what bitwise & does? It takers the logical AND of each bit in the two operands. So, keeping it simple with 2 digit numbers we get 0 = 00 1 = 01 2 = 10 3 = 11 Not

tutor@python.org

2015-10-14 Thread Ben Finney
ਨਿਹੰਗ ਪੰਜਾਬੀ writes: > 'if (n & 1)' below works but I don't understand why/how. Kindly > help. Can you kindly help us understand your confusion? You chose a subject field that indicates why it works, so I don't know what your specific confusion is. -- \“Telling pious lies to trust

tutor@python.org

2015-10-14 Thread Joel Goldstick
On Wed, Oct 14, 2015 at 4:47 PM, ਨਿਹੰਗ ਪੰਜਾਬੀ wrote: > 'if (n & 1)' below works but I don't understand why/how. Kindly help. > > == > >>> def fn(n): > ... if (n & 1): > ... print "n is odd" > ... else: > ... print "n is even" > ... > >>> fn(5) > n is odd > >

tutor@python.org

2015-10-14 Thread ਨਿਹੰਗ ਪੰਜਾਬੀ
'if (n & 1)' below works but I don't understand why/how. Kindly help. == >>> def fn(n): ... if (n & 1): ... print "n is odd" ... else: ... print "n is even" ... >>> fn(5) n is odd >>> fn(4) n is even === Thanks Ni ___

Re: [Tutor] how to unittest cli input

2015-10-14 Thread Peter Otten
Alex Kleider wrote: > On 2015-10-13 14:44, Alex Kleider wrote: >> On 2015-10-13 12:11, Danny Yoo wrote: >> >> >>> ## >>> def make_ask(f, l, p): >>> d = {'Enter your first name: ' : f, >>>'Enter your last name: ' : l, >>>'Your mobile phone #: ' : p}

Re: [Tutor] how to unittest cli input

2015-10-14 Thread Alex Kleider
On 2015-10-14 11:29, Danny Yoo wrote: ## def make_ask(f, l, p): d = {'Enter your first name: ' : f, 'Enter your last name: ' : l, 'Your mobile phone #: ' : p} return d.get ## This is an example of a 'closure' is it not? Y

Re: [Tutor] how to unittest cli input

2015-10-14 Thread Danny Yoo
>>> ## >>> def make_ask(f, l, p): >>> d = {'Enter your first name: ' : f, >>>'Enter your last name: ' : l, >>>'Your mobile phone #: ' : p} >>> return d.get >>> ## > > > This is an example of a 'closure' is it not? Yes, though

Re: [Tutor] how to unittest cli input

2015-10-14 Thread Alex Kleider
On 2015-10-13 14:44, Alex Kleider wrote: On 2015-10-13 12:11, Danny Yoo wrote: ## def make_ask(f, l, p): d = {'Enter your first name: ' : f, 'Enter your last name: ' : l, 'Your mobile phone #: ' : p} return d.get ## This i