Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78726 > unrolled thread
| Started by | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| First post | 2014-10-05 19:02 -0400 |
| Last post | 2014-10-09 15:28 +0000 |
| Articles | 7 on this page of 27 — 12 participants |
Back to article view | Back to comp.lang.python
Practice question Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-05 19:02 -0400
Re: Practice question Roy Smith <roy@panix.com> - 2014-10-05 19:06 -0400
Re: Practice question Ned Batchelder <ned@nedbatchelder.com> - 2014-10-05 19:14 -0400
Re: Practice question Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-05 20:07 -0400
Re: Practice question Ned Batchelder <ned@nedbatchelder.com> - 2014-10-05 21:25 -0400
Re: Practice question Steven D'Aprano <steve@pearwood.info> - 2014-10-07 08:41 +0000
Re: Practice question Skip Montanaro <skip.montanaro@gmail.com> - 2014-10-05 18:33 -0500
Re: Practice question Rustom Mody <rustompmody@gmail.com> - 2014-10-05 19:47 -0700
Re: Practice question Skip Montanaro <skip.montanaro@gmail.com> - 2014-10-06 08:04 -0500
Re: Practice question Rustom Mody <rustompmody@gmail.com> - 2014-10-06 09:23 -0700
Re: Practice question Chris Angelico <rosuav@gmail.com> - 2014-10-07 03:52 +1100
Re: Practice question Rustom Mody <rustompmody@gmail.com> - 2014-10-06 10:05 -0700
Re: Practice question Chris Angelico <rosuav@gmail.com> - 2014-10-07 04:13 +1100
Re: Practice question Steven D'Aprano <steve@pearwood.info> - 2014-10-06 20:49 +0000
Re: Practice question "Redge @ Versalytics.com" <versalytics@gmail.com> - 2014-10-06 20:54 -0400
Re: Practice question Rustom Mody <rustompmody@gmail.com> - 2014-10-08 09:14 -0700
Re: Practice question Chris Angelico <rosuav@gmail.com> - 2014-10-09 03:23 +1100
Re: Practice question Skip Montanaro <skip.montanaro@gmail.com> - 2014-10-08 11:27 -0500
Re: Practice question Rustom Mody <rustompmody@gmail.com> - 2014-10-08 09:41 -0700
Re: Practice question Terry Reedy <tjreedy@udel.edu> - 2014-10-05 19:47 -0400
Re: Practice question Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-05 20:18 -0400
Re: Practice question Steven D'Aprano <steve@pearwood.info> - 2014-10-07 08:48 +0000
Re: Practice question C Smith <illusiontechniques@gmail.com> - 2014-10-07 05:43 -0700
Re: Practice question C Smith <illusiontechniques@gmail.com> - 2014-10-05 16:24 -0700
Re: Practice question Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-07 01:46 +0000
Re: Practice question Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-06 22:06 -0400
Re: Practice question alister <alister.nospam.ware@ntlworld.com> - 2014-10-09 15:28 +0000
Page 2 of 2 — ← Prev page 1 [2]
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Date | 2014-10-05 20:18 -0400 |
| Message-ID | <pnn33a1cqtpbagua005b0cfhb587sfla9t@4ax.com> |
| In reply to | #78730 |
On Sun, 05 Oct 2014 19:47:40 -0400, Terry Reedy <tjreedy@udel.edu>
wrote:
>On 10/5/2014 7:02 PM, 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.
>> So the right answer is 15<= x or x <30
>> but one of the other answers is
>> not (15<= x and x <30)
>>
>> But it says.....remember you can try this out in the Python shell.
>> How?
>
>For instance,
>for x in (10, 20, 30, 40):
> print((15 <= x < 30) == (15<= x and x <30))
I think I get it now. You are using a sample of answers. So you
could actually just run through them all. (I haven't tried this yet)
for x in range(lo,hi)
print((15 <= x < 30) == (15<= x and x <30))
Thanks
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve@pearwood.info> |
|---|---|
| Date | 2014-10-07 08:48 +0000 |
| Message-ID | <5433a8f7$0$2916$c3e8da3$76491128@news.astraweb.com> |
| In reply to | #78732 |
On Sun, 05 Oct 2014 20:18:13 -0400, Seymore4Head wrote:
> I think I get it now. You are using a sample of answers. So you could
> actually just run through them all. (I haven't tried this yet)
>
> for x in range(lo,hi)
> print((15 <= x < 30) == (15<= x and x <30))
Yes, except using print is probably not the best idea, since you might
have dozens of True True True True ... printed, one per line, and if you
blink the odd False might have scrolled off screen before you notice.
With two numbers, 15 and 30, all you really need is five test cases:
- a number lower than the smaller of the two numbers (say, 7);
- a number equal to the smaller of the two numbers (that is, 15);
- a number between the two numbers (say, 21);
- a number equal to the larger of the two numbers (that is, 30);
- a number higher than the larger of the two numbers (say, 999);
The exact numbers don't matter, so long as you test all five cases. And
rather than printing True True True... let's use assert instead:
for x in (7, 15, 21, 30, 999):
assert (15 <= x < 30) == (15<= x and x <30)
If the two cases are equal, assert will do nothing. But if they are
unequal, assert will raise an exception and stop, and you know that the
two cases are not equivalent and can go on to the next possibility.
--
Steven
[toc] | [prev] | [next] | [standalone]
| From | C Smith <illusiontechniques@gmail.com> |
|---|---|
| Date | 2014-10-07 05:43 -0700 |
| Message-ID | <mailman.14658.1412685815.18130.python-list@python.org> |
| In reply to | #78795 |
Steven D'Aprano wrote: >>With two numbers, 15 and 30, all you really need is five test cases: My solution assumed integers also, but after I posted it, I thought: "What about floating points?" On Tue, Oct 7, 2014 at 1:48 AM, Steven D'Aprano <steve@pearwood.info> wrote: > On Sun, 05 Oct 2014 20:18:13 -0400, Seymore4Head wrote: > >> I think I get it now. You are using a sample of answers. So you could >> actually just run through them all. (I haven't tried this yet) >> >> for x in range(lo,hi) >> print((15 <= x < 30) == (15<= x and x <30)) > > Yes, except using print is probably not the best idea, since you might > have dozens of True True True True ... printed, one per line, and if you > blink the odd False might have scrolled off screen before you notice. > > With two numbers, 15 and 30, all you really need is five test cases: > > - a number lower than the smaller of the two numbers (say, 7); > - a number equal to the smaller of the two numbers (that is, 15); > - a number between the two numbers (say, 21); > - a number equal to the larger of the two numbers (that is, 30); > - a number higher than the larger of the two numbers (say, 999); > > > The exact numbers don't matter, so long as you test all five cases. And > rather than printing True True True... let's use assert instead: > > > for x in (7, 15, 21, 30, 999): > assert (15 <= x < 30) == (15<= x and x <30) > > > If the two cases are equal, assert will do nothing. But if they are > unequal, assert will raise an exception and stop, and you know that the > two cases are not equivalent and can go on to the next possibility. > > > -- > Steven > -- > https://mail.python.org/mailman/listinfo/python-list
[toc] | [prev] | [next] | [standalone]
| From | C Smith <illusiontechniques@gmail.com> |
|---|---|
| Date | 2014-10-05 16:24 -0700 |
| Message-ID | <mailman.14625.1412579995.18130.python-list@python.org> |
| In reply to | #78726 |
14<x<=29 On Sun, Oct 5, 2014 at 4:14 PM, Ned Batchelder <ned@nedbatchelder.com> wrote: > On 10/5/14 7:02 PM, 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. >> So the right answer is 15<= x or x <30 > > > No, "15 <= x < 30" is equivalent to "15 <= x and x < 30". > >> but one of the other answers is >> not (15<= x and x <30) > > > You are speaking ambiguously. Which did you mean: > a) one of the other answers isn't "15 <= x and x < 30", or: > b) one of the other answers is "not (15 <= x and x < 30)" ? > > -- > Ned Batchelder, http://nedbatchelder.com > > -- > https://mail.python.org/mailman/listinfo/python-list
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2014-10-07 01:46 +0000 |
| Message-ID | <m0vglt$ppq$1@dont-email.me> |
| In reply to | #78726 |
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
[toc] | [prev] | [next] | [standalone]
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Date | 2014-10-06 22:06 -0400 |
| Message-ID | <tdi63a55gqc3lr6g8mff4qrk8ie9n9i3m9@4ax.com> |
| In reply to | #78786 |
On Tue, 7 Oct 2014 01:46:37 +0000 (UTC), Denis McMahon <denismfmcmahon@gmail.com> wrote: >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" All of the practice questions up to this question had 4 answers. With each question you could verify the correct answers by just copy and pasting each choice into Python. So when the instructions said I could verify this with Python I assumed there might be some way to test if the question was == to each answer.
[toc] | [prev] | [next] | [standalone]
| From | alister <alister.nospam.ware@ntlworld.com> |
|---|---|
| Date | 2014-10-09 15:28 +0000 |
| Message-ID | <TQxZv.411104$J62.399570@fx03.am4> |
| In reply to | #78788 |
On Mon, 06 Oct 2014 22:06:09 -0400, Seymore4Head wrote: > On Tue, 7 Oct 2014 01:46:37 +0000 (UTC), Denis McMahon > <denismfmcmahon@gmail.com> wrote: > >>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" > > All of the practice questions up to this question had 4 answers. With > each question you could verify the correct answers by just copy and > pasting each choice into Python. > > So when the instructions said I could verify this with Python I assumed > there might be some way to test if the question was == to each answer. no you need to type in each snippet of code & see if they give the same result when run. -- In every non-trivial program there is at least one bug.
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.python
csiph-web