Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.kamp.net!newsfeed.kamp.net!feeder1.cambriumusenet.nl!82.197.223.108.MISMATCH!feeder2.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.87.MISMATCH!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'mrab': 0.05; 'subject:Python': 0.06; 'assignment': 0.07; 'fixes': 0.07; 'result,': 0.07; 'excluding': 0.09; 'subject:script': 0.09; 'python': 0.11; 'itself.': 0.14; '(inclusive)': 0.16; 'assignment.': 0.16; 'ignoring': 0.16; 'incorrect': 0.16; 'multiples': 0.16; 'record,': 0.16; 'prevent': 0.16; 'appropriate': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'result.': 0.19; 'code,': 0.22; 'email addr:gmail.com>': 0.22; 'tests': 0.22; 'error': 0.23; 'script': 0.25; '>': 0.26; '(for': 0.26; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'possibility': 0.29; 'tim': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'prints': 0.31; 'yes.': 0.31; 'another': 0.32; 'says': 0.33; 'to:name:python-list': 0.33; 'basic': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'doing': 0.36; 'should': 0.36; 'unit': 0.37; 'requirements': 0.37; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'skip:& 20': 0.39; 'to:addr:python.org': 0.39; 'changed': 0.39; 'university': 0.39; 'skip:\xc2 10': 0.60; 'affect': 0.61; 'numbers': 0.61; 'range': 0.61; 'first': 0.61; 'happen': 0.63; 'sum': 0.64; 'between': 0.67; '26,': 0.68; 'subject:this': 0.83; 'cubes': 0.84; 'rusi': 0.91; 'subject:Check': 0.95; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=Rta8LolVpwijZ46XnFeLoy4b60BPiqWkv9dKKj0XpVQ=; b=jTQpT51xLj94fGtalJSNBgdk3bn9J117DL04OsX9pKnIeXtYJ0MnXHiWSS4ex9y/lO Ml3+oM1G0yH6Nb4ocPR95bDe0JZx9cYDF0zv12zaTMzNPOoCVlhIwvaYThlfaYxTQ9JO bC5rtbrXhgPBBAwhtkGXsANojMr42FYZPwyzrzzXlUrX21iL3LA70qwFD6T10oWa2FHk C9L0Ys+DLdyxsVRZurhPwOkYtMBNZ25MkkYCoO5uCEdU5PjHjMxrl1x0DP9DucwOqF9m AhYN73AN1qnWyFnpENnXMscCktiI+hmfCt84Jkx4YZ4KTrAJ2IPSIll5BEzxus2GB6a3 0gdw== MIME-Version: 1.0 X-Received: by 10.182.213.97 with SMTP id nr1mr2790837obc.48.1382909457986; Sun, 27 Oct 2013 14:30:57 -0700 (PDT) In-Reply-To: References: <9716695c-31e3-40a0-b2a4-73b967494107@googlegroups.com> Date: Mon, 28 Oct 2013 08:30:57 +1100 Subject: Re: Check if this basic Python script is coded right From: Tim Delaney To: Python-List Content-Type: multipart/alternative; boundary=001a11c20afcfffdea04e9bfb2ec X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 85 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1382909888 news.xs4all.nl 15949 [2001:888:2000:d::a6]:48926 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:57766 --001a11c20afcfffdea04e9bfb2ec Content-Type: text/plain; charset=UTF-8 On 27 October 2013 23:20, rusi wrote: > On Saturday, October 26, 2013 11:50:33 PM UTC+5:30, MRAB wrote: > > On 26/10/2013 18:36, HC wrote: > > > I'm doing my first year in university and I need help with this basic > assignment. > > > > > > Assignment: Write Python script that prints sum of cubes of numbers > between 0-200 that are multiples of 3. 3^3+6^3+9^3+12^3....+198^3=? > > > > > > > Is it all okay? > > > > > Just one small point: the assignment says that the numbers should be in > > the range 0-200, but the loop's condition is count<200 it's excluding > > 200, so the numbers will actually be in the range 0-199. > > > > However, as 200 isn't a multiple of 3, it won't affect the result, but > > in another assignment it might. > > > > (For the record, this is known as an "off-by-one" error.) > > So is an off-by-one error that did not happen an off-by-an-off-by-one > error? > I would say yes. When someone realises that the requirements were also off by one and the specification gets changed to "between 0-201" (inclusive) then whoever fixes it might naively just add one to the existing code, giving an incorrect result. Obviously I'm ignoring the possibility of appropriate unit tests to prevent this - just looking at the code itself. Tim Delaney --001a11c20afcfffdea04e9bfb2ec Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On 2= 7 October 2013 23:20, rusi <rustompmody@gmail.com> wrote= :
On Saturday, October 26, 2013 11:50:33 PM UTC+5:30, MRAB = wrote:
> On 26/10/2013 18:36, HC wrote:
> > I'm doing my first year in university= and I need help with this basic assignment.
> >
> > Assignment: Write Python script that prints sum of cubes of numbe= rs between 0-200 that are multiples of 3. 3^3+6^3+9^3+12^3....+198^3=3D?
<code snipped>
> >
> > Is it all okay?
> >
> Just one small point: the assignment says that the numbers should be i= n
> the range 0-200, but the loop's condition is count<200 it's= excluding
> 200, so the numbers will actually be in the range 0-199.
>
> However, as 200 isn't a multiple of 3, it = won't affect the result, but
> in another assignment it might.
>
> (For the record, this is known as an "off-by-one" error.)
So is an off-by-one error that did not happen an off-by-an-off-by-one= error?

I would say yes. When someone r= ealises that the requirements were also off by one and the specification ge= ts changed to =C2=A0"between 0-201" (inclusive) then whoever fixe= s it might naively just add one to the existing code, giving an incorrect r= esult.

Obviously I'm ignoring the possibility of appropria= te unit tests to prevent this - just looking at the code itself.
=
Tim Delaney=C2=A0
--001a11c20afcfffdea04e9bfb2ec--