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


Groups > comp.lang.python > #57642

Re: Check if this basic Python script is coded right

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.024
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'subject:Python': 0.06; 'assignment': 0.07; 'result,': 0.07; 'excluding': 0.09; 'subject:script': 0.09; 'python': 0.11; 'assignment.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'multiples': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'record,': 0.16; 'wrote:': 0.18; 'print': 0.22; 'header :User-Agent:1': 0.23; 'script': 0.25; '(for': 0.26; 'header:In- Reply-To:1': 0.27; "i'm": 0.30; 'prints': 0.31; 'another': 0.32; 'says': 0.33; 'basic': 0.35; 'received:84': 0.35; 'but': 0.35; 'doing': 0.36; 'should': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'university': 0.39; 'affect': 0.61; 'numbers': 0.61; 'range': 0.61; 'first': 0.61; 'sum': 0.64; 'skip:+ 10': 0.65; 'between': 0.67; 'header:Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; 'subject:this': 0.83; 'cubes': 0.84; 'reply-to:addr:python.org': 0.84; 'subject:Check': 0.95
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=PIY2p5aC c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=05MOGALpfCEA:10 a=vw_Mo1RBA30A:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=JisCaoLyyaAA:10 a=Lu2vxdRnIR9GK-OsBcIA:9 a=95Mbylsdwe00HYUg:21 a=U_2EuPi2KZ8Wz3f_:21 a=wPNLvfGTeEIA:10
X-AUTH mrabarnett:2500
Date Sat, 26 Oct 2013 19:20:33 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Thunderbird/24.0.1
MIME-Version 1.0
To python-list@python.org
Subject Re: Check if this basic Python script is coded right
References <9716695c-31e3-40a0-b2a4-73b967494107@googlegroups.com>
In-Reply-To <9716695c-31e3-40a0-b2a4-73b967494107@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To python-list@python.org
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.1594.1382811634.18130.python-list@python.org> (permalink)
Lines 27
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1382811634 news.xs4all.nl 15890 [2001:888:2000:d::a6]:43035
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:57642

Show key headers only | View raw


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=?
>
> My script:
> count = 0
> answer = 0
>
> while count<200:
>      if count%3==0:
>          answer = answer + count**3
>      count = count + 1
>
> print ("Result is: " +str(answer))
>
> 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.)

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