I have an CSV file, which has the current format below.
A two row example of this would be:
first_Name last_Name test1 test2 test3 test4
Alex Brian 11 17 13 24
Pete Tong 19 14 12 30
Now my current code does not work, Simply put I am not sure if I am on the right track. My current code:
def grader(test1, test2, test3, finalExam):
first = test1 * .20
second = test2 * .20
third = test3 * .20
fourth = finalExam *.40
finalGrade = first + second + third + fourth
return finalGrade
def gradeScores(FinalGrade):
if FinalGrade >= 90 and FinalGrade <= 100:
return("You received an A")
elif FinalGrade >= 80 and FinalGrade < 90:
return("You received a B")
elif FinalGrade >= 70 and FinalGrade < 80:
return("You received a C")
elif FinalGrade >= 60 and FinalGrade < 70:
return("You received a D")
else:
return("Sorry, you received an F")
I also have this line of code which is to read the CSV file, and displays in the output window.
with open("studentGradeFrom.csv") as csvfile:
readFile = csv.reader(csvfile, delimiter=",", quotechar="¦")
for row in readFile:
print(row)
However since I am new to Python, I am looking for help to create a python script, that will look at the results and do a calculation which will tell me if the student has passed or failed. I would like this to be done in a separate file. So I am guessing that I will need to read and write to a different CSV file, to show if a student has failed or has an overall passing percentage.
with open("studentGradeTo.csv", 'w') as avg: #used to write to after the calculation is complete
loadeddata = open("studentGradeFrom.csv", 'r') #used to read the data from the CSV before calculation.
writer=csv.writer(avg)
readloaded=csv.reader(loadeddata)
listloaded=list(readloaded)
Now my question: How would I go about doing this, from looking at data from one file which roughly 50 different students. While not changing the read CSV with the student grades, and only changing the CSV file which shows passing or failing grades. Any help would be appreciated.
Edit: I forgot to mention that the first test would be work 20% of the final grade, the same with the second test and third test. these three totalling to 60% of final grade. While the fourth test is worth 40% of the final grade.