Average calculation Program *need help*

Michael Torrie torriem at gmail.com
Fri May 13 00:57:10 EDT 2016


On 05/12/2016 10:22 PM, Jake Kobs wrote:
> On Thursday, May 12, 2016 at 10:48:08 AM UTC-5, Jake Kobs wrote:
>> 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.
>  
> I still can't get it. Someone please tell me lol. I have done everything I can and still I get bad answers.

Tell us what you've done, precisely.  We're here to help you learn, not
give you the answers.

One thing that strikes me is that your while loop doesn't appear to be
indented properly.  You have it running after all the scores have been
inputted in the for loop, but I suspect this isn't what you want.  You
want the while loop to occur each time through the for loop.  Do you
know how to move this while loop to be inside the for loop?



More information about the Python-list mailing list