conditional expression sought

Elaine Jackson elainejackson7355 at home.com
Fri Jan 30 01:07:52 EST 2004


Thanks for your help. I just looked at some values of random.randint(0,1) in my
interpreter, and one of them was 0. Getting nonboolean values from conjunction
and disjunction allows conditional evaluation of expressions; for example:
reciprocal = lambda x: (x!=0 and 1.0/x) or (x==0 and "undefined").

"wes weston" <wweston at att.net> wrote in message
news:6PjSb.138487$6y6.2697536 at bgtnsc05-news.ops.worldnet.att.net...
| Elaine,
|     The last code line:
|
| print "I would have liked this to be B[2] = ",B[2]
|
| prints the value of B[2]; the value you don't want.
| I think what you meant was that you want B[2] to be
| 0.0 not false. bool(0.0) does equal false.
| ---------------------------------------------------
| The code:
|
| A.append(bool(randint(0,1)))
|
| will always yield an A of [true,true,true]
| ---------------------------------------------------
| I didn't know this about python, and I'm not sure I
| like it:
|
| wes at linux:~/amy> python
|
|  >>> print 1.1 and 2.2
| 2.2
|  >>> print 2.2 and 1.1
| 1.1
|  >>> print (1.1 and 2.2)
| 2.2
|
| The order is important. To me, it should be printing true
| and not either number or the last number.
|





More information about the Python-list mailing list