Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #108587
| Path | csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Nick Sarbicki <nick.a.sarbicki@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Average calculation Program *need help* |
| Date | Fri, 13 May 2016 07:10:17 +0000 |
| Lines | 47 |
| Message-ID | <mailman.626.1463123428.32212.python-list@python.org> (permalink) |
| References | <011a2f60-aafd-484f-8cb2-6017aaf1bb29@googlegroups.com> <25510084-74ff-4f7f-b99f-bb29bc675899@googlegroups.com> <CAGuvt93CqfC-yORS-rGYbczSVvobOaGq9mkyB6Fu2-WqpAoRwA@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de EG08AUXax1I2oacJMjgZrgyrr9us1KY602+88lDXvoWA== |
| Return-Path | <nick.a.sarbicki@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'executed': 0.07; 'subject:help': 0.07; 'block.': 0.09; 'executes': 0.09; 'indicates': 0.09; 'loop.': 0.09; 'def': 0.13; 'properly': 0.15; '"your': 0.16; '#this': 0.16; '"your': 0.16; '0):': 0.16; 'finishes': 0.16; 'input.': 0.16; 'looping': 0.16; 'range(0,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'somehow.': 0.16; 'statement.': 0.16; 'wrote:': 0.16; '<': 0.18; 'first.': 0.18; 'ownership': 0.18; 'subject:need': 0.18; '>': 0.18; 'email addr:gmail.com>': 0.18; 'input': 0.18; 'bit': 0.23; 'finished': 0.23; 'header:In-Reply-To:1': 0.24; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'said,': 0.27; 'function': 0.28; 'idea': 0.28; 'indentation': 0.29; 'code:': 0.29; 'reset': 0.29; "i'm": 0.30; 'print': 0.30; 'good.': 0.32; 'statement': 0.32; 'getting': 0.33; 'michael': 0.33; 'gets': 0.35; 'received:google.com': 0.35; 'received:74.125.82': 0.35; 'but': 0.36; 'should': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'starting': 0.37; 'difference': 0.38; 'thank': 0.38; 'means': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'your': 0.60; 'total': 0.62; 'within': 0.64; 'between': 0.65; 'here': 0.66; 'score': 0.76; '100': 0.79; 'number(s)': 0.84; 'number):': 0.84; 'score:': 0.84; 'subject: *': 0.84; 'scores': 0.91; 'subject:*': 0.93 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=w9TbJ87NwDATO+ih99xPMMl/LMWlWDZRtlAY+7oeTIg=; b=xuRjlitjHiIU0k8MWrUqnhL3cfORssPYeXy7OEsFM6Cfg25MbLvxNqyvVBIcoz+cwb zp2unl4YsErtisi/N+NNzTLs0ASiIODyXnT5mlcgEwSD7Nl7xsBJickhI3y3gTb7MRDS u2iWdClON9ObRa56vV0BAwcvJEsP9LpGKvXSvapbKKCKnB1zNI6VBj+nA3kvpFNupuDW Gl7iAMRGQ8UdQchPQHlLrF1n5Q6dIT/d7Hus7mnput8DiZM/46VJPV5GrWaEUsf9JTOK 5YyxgxRJXiBtn01j76wsvpI5vsdzhUeroICdMDMPY6unqkQv6yUrcs5mBctIZ38AOJt1 1Bfw== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=w9TbJ87NwDATO+ih99xPMMl/LMWlWDZRtlAY+7oeTIg=; b=DyGS1SYgDb1zGq4AKtpsQREO7KnQwIFr178ypuK0Shq+S0TBFOPbpiIewUBAVJ2Xru 4Gp/WBfuGCKvSEdW5r0SabIa19RcNofhNxsvGn1wH3nYoSsR+A2AZMQXoPbXfBW+yWYY XovtYYxWez+80lMg1VMtR1ViKZaIj9WMDkSoB9sJk6neuS2eXm7UPsYXt2lxMGTVpOn/ 8RLCZrY7mJOZZBiQz+v9upV6D92md0LqUR5uNHBTtbzyoumYR4eNNj6OCrXYYiNkd5Vi 757TpPun3RjHLoS6iGlZxUBZKcdFg7W+hjAaYrHiMIKlffPWwc2W7rzah2vw0nGUlxjK RsFw== |
| X-Gm-Message-State | AOPr4FU1DUPrwqnEMFEgZRlzhmWznocJQDHQ3gQEX/Jgjo3mzXsrpFgdj6lBpI0/zW5VEbxegUGomPBKU/ZQLw== |
| X-Received | by 10.194.95.198 with SMTP id dm6mr14621448wjb.136.1463123427074; Fri, 13 May 2016 00:10:27 -0700 (PDT) |
| In-Reply-To | <25510084-74ff-4f7f-b99f-bb29bc675899@googlegroups.com> |
| X-Content-Filtered-By | Mailman/MimeDel 2.1.22 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.22 |
| 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> |
| X-Mailman-Original-Message-ID | <CAGuvt93CqfC-yORS-rGYbczSVvobOaGq9mkyB6Fu2-WqpAoRwA@mail.gmail.com> |
| X-Mailman-Original-References | <011a2f60-aafd-484f-8cb2-6017aaf1bb29@googlegroups.com> <25510084-74ff-4f7f-b99f-bb29bc675899@googlegroups.com> |
| Xref | csiph.com comp.lang.python:108587 |
Show key headers only | View raw
On Fri, 13 May 2016, 06:52 Jake Kobs, <kobsx4@gmail.com> wrote:
> Thank you for the help..I think I'm getting closer, but I feel like after
> they enter an invalid number, it should reset the invalid number(s)
> somehow. Here's my updated code:
>
> ------------------------------------------------------------------------------
> #this function will get the total scores
> def getScores(totalScores, number):
> for counter in range(0, number):
> score = input('Enter their score: ')
> if (score < 100 and score > 0):
> totalScores = totalScores + score
> while (score > 100 or score < 0):
>
> print "Your scores must be between 0 and 100."
> score = input('Enter their score: ')
> score = input('Enter their score: ')
> totalScores = totalScores + score
>
>
> return totalScores
>
> ----------------------------------------------------------------------------
> --
>
You're starting to get it which is good.
The if is a good idea to begin with, but your while loop still executes
after the for loop finishes as it is not properly indented.
As Michael said, indentation indicates what statement has ownership of a
block. Currently your while loop has it's own block outside the for loop.
This means it gets executed after your for loop has finished looping
through your range. You want the while to be held within the for loop so it
gets executed immediately after each input statement.
Think. Your if is inside the for loop and gets executed after every input.
Your input is inside the for loop. Your while and it's contents are not in
the for loop and get executed after the for loop finishes. The only
difference that matters here is indentation.
Try solve that bit first.
>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Average calculation Program *need help* kobsx4@gmail.com - 2016-05-12 08:47 -0700
Re: Average calculation Program *need help* Rustom Mody <rustompmody@gmail.com> - 2016-05-12 09:01 -0700
Re: Average calculation Program *need help* Igor Korot <ikorot01@gmail.com> - 2016-05-12 12:06 -0400
Re: Average calculation Program *need help* DFS <nospam@dfs.com> - 2016-05-12 19:45 -0400
Re: Average calculation Program *need help* "Martin A. Brown" <martin@linux-ip.net> - 2016-05-12 09:13 -0700
Re: Average calculation Program *need help* MRAB <python@mrabarnett.plus.com> - 2016-05-12 17:14 +0100
Re: Average calculation Program *need help* Jake Kobs <kobsx4@gmail.com> - 2016-05-12 21:22 -0700
Re: Average calculation Program *need help* Ben Finney <ben+python@benfinney.id.au> - 2016-05-13 14:55 +1000
Re: Average calculation Program *need help* Michael Torrie <torriem@gmail.com> - 2016-05-12 22:57 -0600
Re: Average calculation Program *need help* Jake Kobs <kobsx4@gmail.com> - 2016-05-12 22:03 -0700
Re: Average calculation Program *need help* Michael Torrie <torriem@gmail.com> - 2016-05-12 23:29 -0600
Re: Average calculation Program *need help* DFS <nospam@dfs.com> - 2016-05-13 01:12 -0400
Re: Average calculation Program *need help* Jake Kobs <kobsx4@gmail.com> - 2016-05-12 22:46 -0700
Re: Average calculation Program *need help* Nick Sarbicki <nick.a.sarbicki@gmail.com> - 2016-05-13 07:10 +0000
Re: Average calculation Program *need help* Jake Kobs <kobsx4@gmail.com> - 2016-05-13 08:38 -0700
Re: Average calculation Program *need help* DFS <nospam@dfs.com> - 2016-05-13 12:17 -0400
csiph-web