Practice question

Denis McMahon denismfmcmahon at gmail.com
Mon Oct 6 21:46:37 EDT 2014


On Sun, 05 Oct 2014 19:02:31 -0400, Seymore4Head wrote:

> For the record, I don't want a hint.  I want the answer.
> I see a practice question is similar to this.
> 15 <= x < 30  And it wants a similar expression that is equivalent.

I think part of the problem here is that you don't understand the 
expression.

The expression:

15 <= x < 30

contains two conditions:

15 <= x

x < 30

For the whole expression to be true, both conditions must be true, hence 
the equivalence is:

(15 <= x) and (x < 30)

to test this in python command line, see if the two different expressions 
give the same result for a suitable range of values of x:

for x in range(50):
    if not (15 <= x < 30) == ((15 <= x) and (x < 30)):
        print "discrepancy"

or

for x in range(50):
    if (15 <= x < 30) == ((15 <= x) and (x < 30)):
        print "ok"

-- 
Denis McMahon, denismfmcmahon at gmail.com



More information about the Python-list mailing list