Question: I want to find the average of the list inFile and then I would like to move it to the classscores.

`classgrades.txt` is:

```
Chapman 90 100 85 66 80 55    
Cleese 80 90 85 88    
Gilliam 78 82 80 80 75 77    
Idle 91    
Jones 68 90 22 100 0 80 85    
Palin 80 90 80 90

```

`classcores.txt` is empty

This is what I have so far... what should I do?

```
inFile = open('classgrades.txt','r')
outFile = open('classscores.txt','w')

for line in inFile:
  with open(r'classgrades.txt') as data:
    total_stuff = #Don't know what to do past here

biggest = min(total_stuff)
smallest = max(total_stuff)
print(biggest - smallest)
print(sum(total_stuff)/len(total_stuff))

```

Answer: 
You will need to:  

- split each line by whitespace and slice out all items but the first  

- convert each string value in array to integer  

- sum all of those integer values in the array  

- add the sum for this line to total\_sum  

- add the length of those values (the number of numbers) to total\_numbers 

However, this is only part of the problem... I will leave the rest up to you. This code will not write to the new file, it will simply take an average of all the numbers in the first file. If this isn't exactly what you are asking for, then try playing around with this stuff and you should be able to figure it all out.

```
inFile = open('classgrades.txt','r')
outFile = open('classscores.txt','w')
total_sum = 0
total_values = 0
with open(r'classgrades.txt') as inFile:
  for line in  inFile:
    # split by whitespace and slice out everything after 1st item
    num_strings = line.split(' ')[1:] 

    # convert each string value to an integer
    values = [int(n) for n in num_strings]

    # sum all the values on this line
    line_sum = sum(values)

    # add the sum of numbers in this line to the total_sum
    total_sum += line_sum

    # add the length of values in this line to total_values
    total_numbers += len(values)

average = total_sum // total_numbers  # // is integer division in python3
return average

```
you don't need to open file many times and you should close the files at the end of your program. Below is what I tried hope this works for you:

```
d1 = {}
with open(r'classgrades.txt','r') as fp:
    for line in fp:
        contents = line.strip().split(' ')
        # create mapping of student and his numbers
        d1[contents[0]] = map(int,contents[1:])

with open(r'classscores.txt','w') as fp:
    for key, item in d1.items():
        biggest = min(item)
        smallest = max(item)
        print(biggest - smallest)
        # average of all numbers
        avg = sum(item)/len(item)
        fp.write("%s %s\n"%(key,avg))

```