Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def calculateGrade(mark):
- if mark >= 90:
- return ("Ex",10)
- elif mark >= 80:
- return ("A",9)
- elif mark >= 70:
- return ("B",8)
- elif mark >= 60:
- return ("C",7)
- elif mark >= 50:
- return ("D",6)
- elif mark >= 40:
- return ("P",5)
- else: return ("F",0)
- class Student:
- def __init__(self):
- self.name = ""
- self.marks = []
- self.average = 0
- self.grade = []
- self.credit = []
- def setName(self, name):
- self.name = name
- def setMarks(self,marks):
- self.marks = marks
- def setCredits(self,credit):
- self.credit = credit
- def changeMarks(self, subject, mark):
- if subject >=1 and subject <= len(self.marks):
- self.marks[subject] = mark
- else:
- print("Subject not found!!!")
- def averageMarks(self):
- total = 0
- subjects = len(self.marks)
- if subjects == 0:
- return 0
- for mark in self.marks:
- total = total + mark
- self.average = total/subjects
- return self.average
- def grades(self):
- for mark in self.marks:
- self.grade.append(calculateGrade(mark))
- return self.grade
- def SGPA(self):
- sgpa = 0
- totalCredit = 0
- for i in range(0,len(self.credit)):
- sgpa = sgpa + (self.credit[i] * self.grade[i][1])
- totalCredit = totalCredit + self.credit[i]
- if totalCredit == 0:
- return 0
- return sgpa/totalCredit
- def printInfo(self):
- print("Name:",self.name)
- print("Average Marks:",self.average)
- name = input("Enter the name of the student: ")
- n = int(input("Enter the number of subjects: "))
- print("Enter the marks for each subject")
- marks = []
- for i in range(0,n):
- a = int(input(f"Enter the mark for subject {i+1}: "))
- marks.append(a)
- print("Enter the credit for each subject")
- credit = []
- for i in range(0,n):
- a = int(input(f"Enter the credit for subject {i+1}: "))
- credit.append(a)
- student1 = Student()
- student1.setName(name)
- student1.setMarks(marks)
- student1.setCredits(credit)
- print(f"The average marks obtained by {student1.name} is {student1.averageMarks()}")
- print(f"The grades obtained by {student1.name} in each subject")
- Grade = student1.grades()
- sbj = 1
- for grade,gradePoint in Grade:
- print(f"Subject {sbj}: [ Grade: {grade}, Grade Point: {gradePoint} ]")
- sbj = sbj + 1
- print(f"SGPA: {student1.SGPA()}")
- student1.printInfo()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement