How to make a program in python to do this?

20% of the score comes from the average of 8 Quizzes (each has maximum of 10 points)
20% of the score comes from the average of 2 exams (each has maximum of 100 points)
40% of the score comes from the average of 4 Programming assignments (each has maximum of 100 points)
20% of the total score comes from the final exam (has a maximum of 100 points)


The input to the program will be from a text file which will have some lines of input. Each line of the file will begin with a string followed by a space. Then there will be several numbers separated by white spaces. The string represents the names of the students and the numbers are her scores in different quizzes assignments and exams. The first 8 numbers the quiz scores, the 9th, 10th, 11th and the 12th numbers the assignment scores, the 13th, 14th numbers are exam scores the 15th number is the final exam score. Any numbers after 15 are not important. Also an input file could have more than 3 lines and the program should still be able to calculate the averages for each line. This is what the input files data would look like.


Jim 5 4 7 6 5 7 7 7 96 76 63 56 55 76 89 76
John 9 8 6 7 4 8 6 7 66 56 76 65 55 54 46 76
Bob 6 5 5 7 5 4 4 3 76 65 87 96 67 87 76 78


The output of the program will be a text file that will show the name of the student followed by the weighted average final score.

Does anyone know how this program would be written??

Edited 6 Years Ago by sss33: n/a

Not to sure how to explain without actually writing the code for you, might be more confusing than anything :P.

Using the example input you gave:

you open the file
e.g. file = open("C:/file.txt", "r")
You would use readline()
e.g. x = file.readline()
x now contains the string "Jim 5 4 7 6 5 7 7 7 96 76 63 56 55 76 89 76"
you would then use y = x.split(" ") which puts all the stuff in that string seperated by spaces into an array
so y[0] would = Jim
y[1] = 5
y[2] = 4
etc...

so then you have all the numbers isolated in the "program" ready to use, do the math, output, then read the next line (x = file.readline()) and do the same process again for each line.

Edited 6 Years Ago by Enders_Game: n/a

Not to sure how to explain without actually writing the code for you, might be more confusing than anything :P.

Using the example input you gave:

you open the file
e.g. file = open("C:/file.txt", "r")
You would use readline()
e.g. x = file.readline()
x now contains the string "Jim 5 4 7 6 5 7 7 7 96 76 63 56 55 76 89 76"
you would then use y = x.split(" ") which puts all the stuff in that string seperated by spaces into an array
so y[0] would = Jim
y[1] = 5
y[2] = 4
etc...

so then you have all the numbers isolated in the "program" ready to use, do the math, output, then read the next line (x = file.readline()) and do the same process again for each line.

im still confused heres what i have so far, whats after this

#

def main():
# file for reading
f = open ("J:\my file name.file")
myout = open ("my output.file")

Next, read each record in the file and print it.
After that, split each record and print that. Then decide how you can use this data.

Next, read each record in the file and print it.
After that, split each record and print that. Then decide how you can use this data.

y = x.split(" ") this is giving an error do you know why and what would split the numbers in my file correctly.

Wow, a very nice homework assignment. It will definitely test your Python skills. Once you establish your list for each line, slicing will help you a lot.

This article has been dead for over six months. Start a new discussion instead.