Re: [Tutor] programming exercise in Python

2006-08-09 Thread Alan Gauld
> it's much more useful to write out the complete test case without > preconceptions, without the aid of the code you're trying to test. > This works because: > * Writing out the test cases first can help in writing the > real function. > > Those test cases act as documentation that ot

Re: [Tutor] programming exercise in Python

2006-08-09 Thread Danny Yoo
> I had the program generate the test cases for me, and then inspected > them to verify that they were what I desired. Hi Kermit, Ah. Try not to do that next time. It's way too easy to be convinced that some test is working by just copying the output of the code and looking for reasonable ou

Re: [Tutor] programming exercise in Python

2006-08-09 Thread Kermit Rose
From: Alan Gauld Date: 08/09/06 13:52:09 To: Kermit Rose Cc: tutor@python.org Subject: Re: [Tutor] programming exercise in Python >> # testsum = 0 >> # if k > 0: >> # mult[k-1] = 0 >> # for j in range(k,lenmult): >> # testsum = testsum + mpylist[

Re: [Tutor] programming exercise in Python

2006-08-09 Thread Alan Gauld
>> # testsum = 0 >> # if k > 0: >> # mult[k-1] = 0 >> # for j in range(k,lenmult): >> # testsum = testsum + mpylist[j][1] * mult[j] > > My brain is bending with this bit! I'm not sure if its right or > not... > > for k = 0, checks to see if it may add 1 to mult[0] > for k = 1, sets mult[0] = 0, an

Re: [Tutor] programming exercise in Python

2006-08-09 Thread Kermit Rose
From: Alan Gauld Date: 08/09/06 12:53:59 To: Kermit Rose; tutor@python.org Subject: Re: [Tutor] programming exercise in Python > # lenmult = len(mult) This is pretty redundant, it only saves two characters typing, you might as well do ** hmm I had gotten in the ha

Re: [Tutor] programming exercise in Python

2006-08-09 Thread Alan Gauld
> # lenmult = len(mult) This is pretty redundant, it only saves two characters typing, you might as well do for k in range(len(mult)): > # for k in range(lenmult): > # mult[k] = mult[k] + 1 > # if k == 0: > # if mult[k] == 1: > #mult[k] = 2

Re: [Tutor] programming exercise in Python

2006-08-09 Thread Kermit Rose
From: Danny Yoo Date: 08/09/06 11:01:14 To: Kermit Rose Cc: tutor@python.org Subject: Re: [Tutor] programming exercise in Python On Wed, 9 Aug 2006, Kermit Rose wrote: > I've written tenative code for the incr routine. > > Now to test and possibly debug it.

Re: [Tutor] programming exercise in Python

2006-08-09 Thread Danny Yoo
On Wed, 9 Aug 2006, Kermit Rose wrote: > I've written tenative code for the incr routine. > > Now to test and possibly debug it. Just as a note: it's usually a much better idea to write your test cases first, even before writing any code. It'll give you a better idea of what you want your f