Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #108563
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | "Martin A. Brown" <martin@linux-ip.net> |
| Newsgroups | comp.lang.python |
| Subject | Re: Average calculation Program *need help* |
| Date | Thu, 12 May 2016 09:13:58 -0700 |
| Lines | 75 |
| Message-ID | <mailman.614.1463069649.32212.python-list@python.org> (permalink) |
| References | <011a2f60-aafd-484f-8cb2-6017aaf1bb29@googlegroups.com> <alpine.LSU.2.11.1605120908300.29512@znpeba.jbaqresebt.arg> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=US-ASCII |
| X-Trace | news.uni-berlin.de cBiX7ajri5pbcTtykmediwt82HOg+97s9nxJ/ep9xreg== |
| Return-Path | <martin@linux-ip.net> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.121 |
| X-Spam-Level | * |
| X-Spam-Evidence | '*H*': 0.76; '*S*': 0.00; 'chunk': 0.07; 'subject:help': 0.07; 'cc:addr:python-list': 0.09; 'highlight': 0.09; 'variables': 0.15; '"your': 0.16; 'from:addr:martin': 0.16; 'hint': 0.16; 'range(0,': 0.16; 'range,': 0.16; 'received:hsd1.or.comcast.net': 0.16; 'received:io': 0.16; 'received:or.comcast.net': 0.16; 'received:psf.io': 0.16; 'rewriting': 0.16; 'subject:need': 0.18; 'variable': 0.18; 'all,': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'martin': 0.22; 'are.': 0.22; 'cc:no real name:2**0': 0.22; 'appears': 0.23; 'code,': 0.23; 'code.': 0.23; 'help.': 0.23; 'header:In-Reply- To:1': 0.24; 'figure': 0.27; 'error': 0.27; 'received:24': 0.28; 'function': 0.28; 'loop,': 0.29; "i'm": 0.30; 'print': 0.30; '(including': 0.30; 'code': 0.30; 'programmers': 0.30; 'supposed': 0.31; '--------': 0.32; 'aside': 0.32; 'statement': 0.32; 'maybe': 0.33; 'run': 0.33; 'point': 0.33; 'problem': 0.33; 'received:comcast.net': 0.33; "i'll": 0.33; 'skip:- 10': 0.34; 'quite': 0.35; 'something': 0.35; 'problem.': 0.35; 'sometimes': 0.35; 'but': 0.36; 'smaller': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'suggestion': 0.37; 'charset:us-ascii': 0.37; 'names': 0.38; 'test': 0.39; 'does': 0.39; 'still': 0.40; 'ever': 0.60; 'your': 0.60; 'received:network': 0.61; 'total': 0.62; 'different': 0.63; 'hours': 0.65; 'between': 0.65; 'beat': 0.66; 'afraid': 0.67; 'greetings': 0.71; 'score': 0.76; '#1:': 0.84; '#2:': 0.84; "'while'": 0.84; '(rustom': 0.84; '(while': 0.84; '>def': 0.84; '>if': 0.84; 'number):': 0.84; 'score:': 0.84; 'subject: *': 0.84; 'suggestion,': 0.84; 'scores': 0.91; 'average': 0.93; 'subject:*': 0.93; 'examine': 0.95; 'luck': 0.95 |
| X-X-Sender | mabrown@macron.wonderfrog.net |
| In-Reply-To | <011a2f60-aafd-484f-8cb2-6017aaf1bb29@googlegroups.com> |
| 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 | <alpine.LSU.2.11.1605120908300.29512@znpeba.jbaqresebt.arg> |
| X-Mailman-Original-References | <011a2f60-aafd-484f-8cb2-6017aaf1bb29@googlegroups.com> |
| Xref | csiph.com comp.lang.python:108563 |
Show key headers only | View raw
Greetings kobsx4,
>Hello all, I have been struggling with this code for 3 hours now
>and I'm still stumped. My problem is that when I run the following
>code:
>------------------------------------------------------------------------------
>#this function will get the total scores
>def getScores(totalScores, number):
> for counter in range(0, number):
> score = input('Enter their score: ')
> totalScores = totalScores + score
>
> while not (score >= 0 and score <= 100):
>
> print "Your score must be between 0 and 100."
> score = input('Enter their score: ')
>
>
>
> return totalScores
>------------------------------------------------------------------------------
>the program is supposed to find the average of two test scores and
>if one of the scores is out of the score range (0-100), an error
>message is displayed. The main problem with this is that when
>someone types in a number outside of the range, it'll ask them to
>enter two scores again, but ends up adding all of the scores
>together (including the invalid ones) and dividing by how many
>there are. Please help.
Suggestion #1:
--------------
When you are stuck on a small piece of code, set it aside (stop
looking at it) and start over again; sometimes rewriting with
different variable names and a clean slate helps to highlight the
problem.
Professional programmers will tell you that they are quite
accustomed to 'throwing away' code. Don't be afraid to do it.
(While you are still learning, you might want to keep the old chunk
of code around to examine so that you can maybe figure out what you
did wrong.)
Suggestion #2:
--------------
Put a print statement or two in the loop, so that you see how your
variables are changing. For example, just before your 'while' line,
maybe something like:
print "score=%d totalScores=%d" % (score, totalScores,)
Suggestion #3:
--------------
Break the problem down even smaller (Rustom Mody appears to have
beat me to the punch on that suggestion, so I'll just point to his
email.)
Hint #1:
--------
What is the value of your variable totalScores each time through the
loop? Does it ever get reset?
Good luck with your degubbing!
-Martin
--
Martin A. Brown
http://linux-ip.net/
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