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


Groups > comp.lang.python > #57640

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.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.04; 'subject:Python': 0.06; 'lawrence': 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; 'tismer': 0.09; 'python': 0.11; 'assignment.': 0.16; 'multiples': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'language': 0.16; 'wrote:': 0.18; 'programming': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'script': 0.25; 'second': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; "i'm": 0.30; 'prints': 0.31; 'basic': 0.35; 'but': 0.35; 'doing': 0.36; 'christian': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'university': 0.39; 'received:org': 0.40; 'numbers': 0.61; 'world.': 0.61; 'first': 0.61; 'sum': 0.64; 'skip:+ 10': 0.65; 'between': 0.67; 'subject:this': 0.83; 'cubes': 0.84; 'received:2': 0.84; 'subject:Check': 0.95
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: Check if this basic Python script is coded right
Date Sat, 26 Oct 2013 18:55:12 +0100
References <9716695c-31e3-40a0-b2a4-73b967494107@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host host-2-98-201-160.as13285.net
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.0.1
In-Reply-To <9716695c-31e3-40a0-b2a4-73b967494107@googlegroups.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.1593.1382810134.18130.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1382810134 news.xs4all.nl 15910 [2001:888:2000:d::a6]:33765
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:57640

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?
>
> Regards
>

Simplify it by using a for loop with range(count) and you can also write 
answer += count**3.

-- 
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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