Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #57766

Re: Check if this basic Python script is coded right

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 <timothy.c.delaney@gmail.com>
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&gt;': 0.22; 'tests': 0.22; 'error': 0.23; 'script': 0.25; '&gt;': 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 <d255467a-c965-4fbb-960e-ff532618fdef@googlegroups.com>
References <9716695c-31e3-40a0-b2a4-73b967494107@googlegroups.com> <mailman.1594.1382811634.18130.python-list@python.org> <d255467a-c965-4fbb-960e-ff532618fdef@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 <timothy.c.delaney@gmail.com>
To Python-List <python-list@python.org>
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1664.1382909888.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On 27 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 numbers
> between 0-200 that are multiples of 3. 3^3+6^3+9^3+12^3....+198^3=?
> <code snipped>
> > >
> > > 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Check if this basic Python script is coded right HC <hikmat@jafarli.net> - 2013-10-26 10:36 -0700
  Re: Check if this basic Python script is coded right Joel Goldstick <joel.goldstick@gmail.com> - 2013-10-26 13:53 -0400
  Re: Check if this basic Python script is coded right Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-10-26 18:55 +0100
  Re: Check if this basic Python script is coded right John Ladasky <john_ladasky@sbcglobal.net> - 2013-10-26 10:58 -0700
  Re: Check if this basic Python script is coded right MRAB <python@mrabarnett.plus.com> - 2013-10-26 19:20 +0100
    Re: Check if this basic Python script is coded right rusi <rustompmody@gmail.com> - 2013-10-27 05:20 -0700
      Re: Check if this basic Python script is coded right Tim Delaney <timothy.c.delaney@gmail.com> - 2013-10-28 08:30 +1100
  Re: Check if this basic Python script is coded right Terry Reedy <tjreedy@udel.edu> - 2013-10-26 15:46 -0400
  Re: Check if this basic Python script is coded right Terry Reedy <tjreedy@udel.edu> - 2013-10-26 16:16 -0400

csiph-web