Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Denis McMahon Newsgroups: comp.lang.python Subject: Re: Practice question Date: Tue, 7 Oct 2014 01:46:37 +0000 (UTC) Organization: A noiseless patient Spider Lines: 39 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Tue, 7 Oct 2014 01:46:37 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="66ffcfa4470a58bcddbdcd1913f98ab4"; logging-data="26426"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/90HJwyOZqzahyiqirDv+RUdNyZ8GsLl4=" User-Agent: Pan/0.136 (I'm far too busy being delicious; GIT 926a150 git://git.gnome.org/pan2) Cancel-Lock: sha1:d5pdmHvrmM1wchgklVwVMvxw4z8= Xref: csiph.com comp.lang.python:78786 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@gmail.com