# Determining Average Program help

Page 1 of 1

## 3 Replies - 760 Views - Last Post: 12 May 2016 - 10:01 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=393186&amp;s=712d75fd628d7222041fc5f5b2ad151f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 kobs20

Reputation: 0
• Posts: 50
• Joined: 07-May 16

# Determining Average Program help

Posted 11 May 2016 - 07:32 PM

This isn't necessarily an error, but incorrect formatting or something:
```#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 score > 100 or score < 0:

print "Your scores must be between 0 and 100."
score = input('Enter their score: ')

```

This is the output once I type in 2 invalid numbers followed by valid ones.
```How many students took the test: 2
Enter their score: 555
Enter their score: 444
Your scores must be between 0 and 100.
Enter their score: 34
The average test score is 499
Do you want to end program? (Enter no to process a new set of scores):
```

As you can see, it wont even let me type in 2 more scores after the first two invalid ones. Plus, it averages the three numbers.. Please help

Is This A Good Question/Topic? 0

## Replies To: Determining Average Program help

### #2 kobs20

Reputation: 0
• Posts: 50
• Joined: 07-May 16

## Re: Determining Average Program help

Posted 11 May 2016 - 08:11 PM

### #3 ndc85430

• I think you'll find it's "Dr"

Reputation: 1025
• Posts: 3,942
• Joined: 13-June 14

## Re: Determining Average Program help

Posted 11 May 2016 - 09:07 PM

Don't you want to validate each score? Given that information, where do you think that while loop should be?

A couple of other things:

1. Why are you both passing totalScores and returning it? You should either calculate the total locally and return it, or pass the variable in which to hold the total and modify it. There's no need to do both.

2. You don't need to pass the 0 to range(), since per the documentation, the start argument defaults to 0.

### #4 CurlyJoe

Reputation: 22
• Posts: 97
• Joined: 19-September 13

## Re: Determining Average Program help

Posted 12 May 2016 - 10:01 AM

Quote

1. Why are you both passing totalScores and returning it?
Each function call increases the value in totalScores, so the function has to know what the score is now, and also has to return it after adding the next score.

Quote

As you can see, it wont even let me type in 2 more scores after the first two invalid ones.
Good job of testing to catch this. The while() is on the same indentation level as the for(), so gets an entry after the for() has executed.

```def getScores(totalScores, number):
for counter in range(0, number):
score = input('Enter their score: ')
while score > 100 or score < 0:

print "Your scores must be between 0 and 100."
score = input('Enter their score: ')
## only add after a "good" score was input
totalScores = totalScores + score