Can someone please help me, currently I am writing a code for an assignment that extracts the marks and the matrix number from a .txt file and grade the marks into GPA and a grade (A+, A, A-,...) and if the subject needs to be resit (UK), after that it has to find the average GPA of each student to give it an academic performance rating (>=2.00:PS,1.5<=GPA<2.00:CPS,>1.5:FS), It also needs to be sorted according to the average GPA and create an output .txt file.
The code I've written so far seems to be running but I'm not sure what it is doing in the second part of the code or if it is even working. Also, there are some parts which I have no idea how to code, To the amazing people of the Python Forum, pls help me T-T I reaching the deadline soon and my teammates are even more lost.
The .txt file
Thank you, XD
Edit: The code using BBcode and PS. I just started python as part of my course and I suck at it.
The code I've written so far seems to be running but I'm not sure what it is doing in the second part of the code or if it is even working. Also, there are some parts which I have no idea how to code, To the amazing people of the Python Forum, pls help me T-T I reaching the deadline soon and my teammates are even more lost.
class GPA(object):
arg1 = None
arg2 = None
Scale = None
credit = None
initsubject = 0
initGetMarks = 0
totalGPA = 0
Student = [40]
def collection(self): #change the path to the address of the python_data.txt on your computer
path = "D:\\BEEE\\Sem 4\\Master class Pytho programming\\Assignment\\python_data.txt"
book = open(path)
i = 0
for a in book:
j = 0
for b in book:
if b != 0:
newline = b.split("\t")
#print(newline)
Sdata = Student(newline[1],newline[2:10])
self.Student.append(Sdata)
j += 1
p = 0
for item in self.Student[j].data:
self.Student[j].data[p] = round(float(self.Student[j].data[p]))
p += 1
i += 1
print(self.Student[1].data)
self.Grading
def Grading(self): #not fixed yet pls help T-T
#is it possible to use dictionary for this part? if yes pls do it to optimise this part
h = 0
for j in self.Student.S_name:
k = 0
for m in self.Student.data:
if (self.Student[h].data[k] >= 90 and self.Student[h].data[k] == 100):
self.Student[h].GPA[k] += 4.0
self.Student[h].Grade[k] = "A+"
self.Student[h].Resit[k] = ""
elif (self.Student[h].data[k] >= 80 and self.Student[h].data[k] < 89):
self.Student[h].GPA[k] += 4.0
self.Student[h].Grade[k] = "A"
self.Student[h].Resit[k] = ""
elif (self.Student[h].data[k] >= 75 and self.Student[h].data[k] < 79):
self.Student[h].GPA[k] += 3.67
self.Student[h].Grade[k] = "A-"
self.Student[h].Resit[k] = ""
elif (int(self.Student[h].data[k]) >= 70 and int(self.Student[h].data[k]) < 74):
self.Student[h].GPA[k] += 3.33
self.Student[h].Grade[k] = "B+"
self.Student[h].Resit[k] = ""
elif (self.Student[h].data[k] >= 65 and self.Student[h].data[k] < 69):
self.Student[h].GPA[k] += 3.00
self.Student[h].Grade[k] = "B"
self.Student[h].Resit[k] = ""
elif (self.Student[h].data[k] >= 60 and self.Student[h].data[k] < 64):
self.Student[h].GPA[k] += 2.67
self.Student[h].Grade[k] = "B-"
self.Student[h].Resit[k] = ""
elif (self.Student[h].data[k] >= 55 and self.Student[h].data[k] < 59):
self.Student[h].GPA[k] += 2.33
self.Student[h].Grade[k] = "C+"
self.Student[h].Resit[k] = ""
elif (self.Student[h].data[k] >= 50 and self.Student[h].data[k] < 54):
self.Student[h].GPA[k] += 2.00
self.Student[h].Grade[k] = "C"
self.Student[h].Resit[k] = ""
elif (self.Student[h].data[k] >= 45 and self.Student[h].data[k] < 49):
self.Student[h].GPA[k] += 1.67
self.Student[h].Grade[k] = "C-"
self.Student[h].Resit[k] = "(UK)"
elif (self.Student[h].data[k] >= 40 and self.Student[h].data[k] < 44):
self.Student[h].GPA[k] += 1.33
self.Student[h].Grade[k] = "D+"
self.Student[h].Resit[k] = "(UK)"
elif (self.Student[h].data[k] >= 35 and self.Student[h].data[k] < 39):
self.Student[h].GPA[k] += 1.00
self.Student[h].Grade[k] = "D"
self.Student[h].Resit[k] = "(UK)"
elif (self.Student[h].data[k] >= 30 and self.Student[h].data[k] < 35):
self.Student[h].GPA[k] += 0.67
self.Student[h].Grade[k] = "D-"
self.Student[h].Resit[k] = "(UK)"
else:
self.Student[h].GPA[k] += 0.00
self.Student[h].Grade[k] = "F"
self.Student[h].Resit[k] = "(UK)"
self.Student[h].Average += self.Student[h].GPA[k]
k += 1
h += 1
print(self.Student[1].data)
self.sorting()
def sorting(self): # This is the sorting part and the average grade with the performance rating i guess
sortedStudent = sorted(self.Student, key=self.Student.Average)
#def output(self): #writing the output file
class Student():
def __init__(self,name,marks):
self.S_name = name
self.data = marks
self.NoSub = 9
self.GPA = 0
self.Grade = []
self.Resit = []
self.Average = 0
if __name__=='__main__':
init = GPA()
init.collection()The python code The .txt file
Thank you, XD
Edit: The code using BBcode and PS. I just started python as part of my course and I suck at it.
