(adsbygoogle = window.adsbygoogle || []).push({}); 1. The problem statement, all variables and given/known data

I'm suppose to write up a program where I need to take a file that contains a list of

numbers. Example:

30

40

40

80

and so on, these number represent letter grades. 90~100 = „A‟, 80~89 = „B‟, 70~79 = „C‟, 60~69 = „D‟, all other scores = „F‟. So what I'm suppose to do for part of the homework is to separate the numbers into letter grades and then calculate the value of the average scores. The complete homework asks for a graph as well, but I'll figure that out as soon as I get this.

3. The attempt at a solution

Ok I got my program to open the file, by inputing the filename and etc. and its a dat file with a list of numbers. I do a loop for line in homework.readlines(): and converted the numbers (read as a string I believe) into integers using h = int(line) i think i'm running into a problem here because the numbers are not being calculated properly. Then I counted the number of each of the score using

scorecount = [0]*101

scorecount[h]=scorecount[h]+1

From here my question being, is it possible to do a sum calculation within the scorecount? like instead of doing scorecount[1]+scorecount[2]+scorecount[3], is it possible to find the sum by doing a range? like sum(scorecount[range(1-3)]) or somethign along those lines... I tried doing it the normal way but i end up with a sum of 0 for the counts of each number for the letter =/

That's one problem that I'm having, - For Average calculation I was able to get that you can divide by the sum of the total values found for A, B, C, D and F and on teh top you can get the sum of all of them by scorecount[line]*line for every number, (thing is I want to do that as well as add each and every number together so its like count[1]*1+count[2]*2...etc so say there was a count of 3 ones and 2 twos so it'd be like 3*1+2*2) I don't know how to write that out for python...my guess would be something using sum()

Example of the problem if there are two 90s, then scorecount[line]*line ~ scorecount[90] * 90 ~ 2 *90. What I want is for each of the line of numbers to be added to one another.

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Homework Help: Python: Calculating the average of scores and separatign into letter grades

**Physics Forums | Science Articles, Homework Help, Discussion**