Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #57654
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.011 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'mrab': 0.05; 'subject:Python': 0.06; 'assignment': 0.07; 'result,': 0.07; 'interpreted': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:script': 0.09; 'python': 0.11; 'jan': 0.12; 'assignment.': 0.16; 'multiples': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'record,': 0.16; 'reedy': 0.16; 'wrote:': 0.18; 'print': 0.22; 'header:User-Agent:1': 0.23; 'script': 0.25; '(for': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; "i'm": 0.30; 'exclude': 0.31; 'prints': 0.31; 'another': 0.32; 'says': 0.33; 'could': 0.34; 'problem': 0.35; 'basic': 0.35; 'but': 0.35; 'doing': 0.36; 'should': 0.36; 'clear': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'university': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'affect': 0.61; 'numbers': 0.61; 'range': 0.61; 'received:173': 0.61; 'first': 0.61; 'sum': 0.64; 'skip:+ 10': 0.65; 'between': 0.67; 'ranges': 0.74; 'subject:this': 0.83; 'cubes': 0.84; 'given.': 0.84; 'received:fios.verizon.net': 0.84; 'careful': 0.91; 'subject:Check': 0.95 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Terry Reedy <tjreedy@udel.edu> |
| Subject | Re: Check if this basic Python script is coded right |
| Date | Sat, 26 Oct 2013 15:46:43 -0400 |
| References | <9716695c-31e3-40a0-b2a4-73b967494107@googlegroups.com> <526C07F1.7070501@mrabarnett.plus.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | pool-173-59-117-133.phlapa.fios.verizon.net |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.0.1 |
| In-Reply-To | <526C07F1.7070501@mrabarnett.plus.com> |
| 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.1602.1382816824.18130.python-list@python.org> (permalink) |
| Lines | 39 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1382816824 news.xs4all.nl 16000 [2001:888:2000:d::a6]:51133 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:57654 |
Show key headers only | View raw
On 10/26/2013 2:20 PM, 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=?
>>
>> 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.
'Between 0-200' could well be interpreted to exclude both 0 and 200 and
to mean 'in 1-190'. Problem posers should be clear about ranges and
students should be careful to understand the problem given.
> 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.)
Unfortunately common.
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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