Python Forum
Student grader and sorter for assignment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Student grader and sorter for assignment
#1
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.

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.
Reply
#2
(Feb-08-2021, 08:39 AM)RazeAD Wrote: 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.
How so that you write it, but don't know what it is doing or if it is working... :-)

Also we prefer to have your code as well as the sample text file here on the forum. You can copy/patse here as text using BBCode tags. See BBcode help for more info.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Starting at the def Grading(self) part, at first it gave an error but after changing the for loop it just operated and debug wasn't showing anything
Reply
#4
Can you please give us the full assignment text?

Also, I agree with @buran that it is a strange situation with someone coding without understanding the code he/she wrote.
Reply
#5
Task
You are required to produce a Python Program to grade the marks and calculate the Grade Point Average (GPA) for a group of Electrical & Electronic Engineering Students. The list of students, subjects taken, and marks are given in the file python_data.txt. To complete the task, you have to read the data file provided and produce a separate data file to include the following:
1. Grade for the courses based on the marks obtained by each student
2. Indicate whether the student is required to repeat the subject with the notation (UK)
3. GPA for each student
4. Based on the GPA, indicate the status of student’s results based on Pass Status (PS), Condition Pass Status (CPS), or Failed Status (FS).
5. Sort the students based on their GPAs, from high to low.

The Python code (e.g., relevant comments, structure, simplicity, uses of functions/arrays/list, no warnings/errors and etc) and the output file (e.g., completeness/ accuracy of the information required) will also be assessed. By the end of the project, you need to submit 3-pages report containing:
1. Introduction
2. Problem Statement
3. Methodology (Flow Chart/ Algorithm)
4. Discussion (e.g., Difficulties/challenges in setting up the code? Any strategy you adopted that makes the code more efficient or user friendly?)
5. Conclusion

Note: For project submission, please include only three (3) files: 1) Python Program, 2) data file created and 3) 3 to 5 pages report (in PDF).

Marks Grade Grade Point
90-100 A+ 4.00
80-89 A 4.00
75-79 A- 3.67
70-74 B+ 3.33
65-69 B 3.00
60-64 B- 2.67
55-59 C+ 2.33
50-54 C 2.00
45-49 C- 1.67
40-44 D+ 1.33
35-39 D 1.00
30-34 D- 0.67
<30 F 0

*The minimum passing grade is 50% in which any marks less than this will require the students to repeat the subject.

Academic Performance Rating GPA
PS - Pass Status GPA ≥ 2.00
CPS - Condition Pass Status 1.50 ≤ GPA < 2.00
FS – Failed Status GPA < 1.50

This is the assignment
Reply
#6
(Feb-08-2021, 09:14 AM)Serafim Wrote: Can you please give us the full assignment text?

Also, I agree with @buran that it is a strange situation with someone coding without understanding the code he/she wrote.

Made a mistake in phrasing that part, it should be when the program is ran the grading part seems to be skipped instead of running and it doesn’t seem to be doing anything
Reply
#7
Good day to everyone XD,

I'm currently writing a program to read a .txt file and grade and sort the data according to GPA. currently stuck on how to sort and write the file, the deadline is today so pls teach me how to fix the problem.

Thank you XD
class Grader(object):
    arg1 = None
    arg2 = None
    Scale = None
    credit = None
    initsubject = 0
    initGetMarks = 0
    totalGPA = 0.00
    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")
                    course = a.split("\t")
                    #print(course)
                    # print(newline)
                    Sdata = Student(newline[1], newline[2:11], course[2:11])
                    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
        for h in range(40):
            h += 1
            for k in range(9):
                if (self.Student[h].data[k] >= 90 and self.Student[h].data[k] <= 100):
                    self.Student[h].GPA += float(4.00)
                    self.Student[h].Grade.append("A+")
                    self.Student[h].Resit.append("")
                elif (self.Student[h].data[k] >= 80 and self.Student[h].data[k] <= 89):
                    self.Student[h].GPA += (float(4.00) * self.Student[h].Subject[k])
                    self.Student[h].Grade.append("A")
                    self.Student[h].Resit.append("")
                elif (self.Student[h].data[k] >= 75 and self.Student[h].data[k] <= 79):
                    self.Student[h].GPA += (float(3.67) * self.Student[h].Subject[k])
                    self.Student[h].Grade.append("A-")
                    self.Student[h].Resit.append("")
                elif (int(self.Student[h].data[k]) >= 70 and int(self.Student[h].data[k]) <= 74):
                    self.Student[h].GPA += (float(3.33) * self.Student[h].Subject[k])
                    self.Student[h].Grade.append("B+")
                    self.Student[h].Resit.append("")
                elif (self.Student[h].data[k] >= 65 and self.Student[h].data[k] <= 69):
                    self.Student[h].GPA += (float(3.00) * self.Student[h].Subject[k])
                    self.Student[h].Grade.append("B")
                    self.Student[h].Resit.append("")
                elif (self.Student[h].data[k] >= 60 and self.Student[h].data[k] <= 64):
                    self.Student[h].GPA += (float(2.67) * self.Student[h].Subject[k])
                    self.Student[h].Grade.append("B-")
                    self.Student[h].Resit.append("")
                elif (self.Student[h].data[k] >= 55 and self.Student[h].data[k] <= 59):
                    self.Student[h].GPA += (float(2.33) * self.Student[h].Subject[k])
                    self.Student[h].Grade.append("C+")
                    self.Student[h].Resit.append("")
                elif (self.Student[h].data[k] >= 50 and self.Student[h].data[k] <= 54):
                    self.Student[h].GPA += (float(2.00) * self.Student[h].Subject[k])
                    self.Student[h].Grade.append("C")
                    self.Student[h].Resit.append("")
                elif (self.Student[h].data[k] >= 45 and self.Student[h].data[k] <= 49):
                    self.Student[h].GPA += (float(1.67) * self.Student[h].Subject[k])
                    self.Student[h].Grade.append("C-")
                    self.Student[h].Resit.append("UK")
                elif (self.Student[h].data[k] >= 40 and self.Student[h].data[k] <= 44):
                    self.Student[h].GPA += (float(1.33) * self.Student[h].Subject[k])
                    self.Student[h].Grade.append("D+")
                    self.Student[h].Resit.append("UK")
                elif (self.Student[h].data[k] >= 35 and self.Student[h].data[k] <= 39):
                    self.Student[h].GPA += (float(1.00) * self.Student[h].Subject[k])
                    self.Student[h].Grade.append("D")
                    self.Student[h].Resit.append("UK")
                elif (self.Student[h].data[k] >= 30 and self.Student[h].data[k] < 34):
                    self.Student[h].GPA += (float(0.67) * self.Student[h].Subject[k])
                    self.Student[h].Grade.append("D-")
                    self.Student[h].Resit.append("UK")
                else:
                    self.Student[h].GPA += (float(0) * self.Student[h].Subject[k])
                    self.Student[h].Grade.append("F")
                    self.Student[h].Resit.append("UK")
            self.Student[h].GPA = self.Student[h].GPA / 21
        print("Finish")
        self.sorting()

    def sorting(self):  # This is the sorting part and the average grade with the performance rating i guess
        for p in range(40):
            p += 1
            if self.Student[p].GPA >= 2.00:
                self.Student[p].Rating.append("PS")
            elif 1.50 <= self.Student[p].GPA <= 1.99:
                self.Student[p].Rating.append("CPS")
            else:
                self.Student[p].Rating.append("FS")
        sorted(self.Student, key=lambda x:float(x), reverse=True)
        self.output()

    def output(self): # writing the output file
        f = open("output_file.txt","w+")
        header = "Matric_card_no\t"
        for final in range(40):
            header += Student.course + "\t\t"
        f.write(header + "\n")
        for student in range(40):
            S_list = Student.S_name
            for score in Student.data:
                S_list += str(Student.data) + "(" + Student.grade + \
                ")[" + Student.Rating + "]" + Student.Resit + "\t"
                f.write(S_list + "\n")


class Student():
    def __init__(self, name, marks, course):
        self.S_name = name
        self.data = marks
        self.course = course
        self.Subject = [3, 3, 2, 2, 2, 3, 2, 2, 2]
        self.GPA = 0.00
        self.Grade = []
        self.Resit = []
        self.Rating = []


if __name__ == '__main__':
    init = Grader()
    init.collection()
The .txt file
edit:typo XP
buran write Feb-11-2021, 06:18 AM:
Please, don't start new threads unnecessarily. Threads merged.
Reply
#8
(Feb-11-2021, 02:18 AM)RazeAD Wrote: Please, don't start new threads unnecessarily. Threads merged.
Okay, thank you for telling me XD
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Student project - alert action when X happens Y amt of times, how? unknown00 2 2,422 Aug-25-2021, 08:07 PM
Last Post: namarang
  Generating a student's transcript [OOP concept] aongkeko 2 3,546 Dec-01-2020, 06:43 AM
Last Post: buran
  Create code for input names and score for 15 student Davin 2 2,820 Sep-21-2020, 08:49 AM
Last Post: DeaD_EyE
  New Python Student = Does this code look right? musicjoeyoung 6 4,787 May-07-2020, 02:39 PM
Last Post: musicjoeyoung
  Student grade program help debug ccm1776 3 7,994 Nov-14-2018, 02:41 AM
Last Post: stullis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020