Advertisement
ruhan008

Q13

Apr 21st, 2024
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.61 KB | None | 0 0
  1. def calculateGrade(mark):
  2.     if mark >= 90:
  3.         return ("Ex",10)
  4.     elif mark >= 80:
  5.         return ("A",9)
  6.     elif mark >= 70:
  7.         return ("B",8)
  8.     elif mark >= 60:
  9.         return ("C",7)
  10.     elif mark >= 50:
  11.         return ("D",6)
  12.     elif mark >= 40:
  13.         return ("P",5)
  14.     else: return ("F",0)
  15.  
  16. class Student:
  17.     def __init__(self):
  18.  
  19.         self.name = ""
  20.         self.marks = []
  21.         self.average = 0
  22.         self.grade = []
  23.         self.credit = []
  24.  
  25.     def setName(self, name):
  26.         self.name = name
  27.    
  28.     def setMarks(self,marks):
  29.         self.marks = marks
  30.    
  31.     def setCredits(self,credit):
  32.         self.credit = credit
  33.  
  34.     def changeMarks(self, subject, mark):
  35.         if subject >=1 and subject <= len(self.marks):
  36.             self.marks[subject] = mark
  37.         else:
  38.             print("Subject not found!!!")
  39.        
  40.     def averageMarks(self):
  41.         total = 0
  42.         subjects = len(self.marks)
  43.         if subjects == 0:
  44.             return 0
  45.         for mark in self.marks:
  46.             total = total + mark
  47.        
  48.         self.average = total/subjects
  49.  
  50.         return self.average
  51.    
  52.     def grades(self):
  53.         for mark in self.marks:
  54.             self.grade.append(calculateGrade(mark))
  55.        
  56.         return self.grade
  57.  
  58.     def SGPA(self):
  59.         sgpa = 0
  60.         totalCredit = 0
  61.         for i in range(0,len(self.credit)):
  62.             sgpa = sgpa + (self.credit[i] * self.grade[i][1])
  63.             totalCredit = totalCredit + self.credit[i]
  64.        
  65.         if totalCredit == 0:
  66.             return 0
  67.         return sgpa/totalCredit
  68.  
  69.     def printInfo(self):
  70.         print("Name:",self.name)
  71.         print("Average Marks:",self.average)
  72.  
  73. name = input("Enter the name of the student: ")
  74. n = int(input("Enter the number of subjects: "))
  75. print("Enter the marks for each subject")
  76. marks = []
  77. for i in range(0,n):
  78.     a = int(input(f"Enter the mark for subject {i+1}: "))
  79.     marks.append(a)
  80.  
  81. print("Enter the credit for each subject")
  82. credit = []
  83. for i in range(0,n):
  84.     a = int(input(f"Enter the credit for subject {i+1}: "))
  85.     credit.append(a)
  86.  
  87. student1 = Student()
  88. student1.setName(name)
  89. student1.setMarks(marks)
  90. student1.setCredits(credit)
  91.  
  92. print(f"The average marks obtained by {student1.name} is {student1.averageMarks()}")
  93. print(f"The grades obtained by {student1.name} in each subject")
  94. Grade = student1.grades()
  95. sbj = 1
  96. for grade,gradePoint in Grade:
  97.     print(f"Subject {sbj}: [ Grade: {grade}, Grade Point: {gradePoint} ]")
  98.     sbj = sbj + 1
  99.  
  100. print(f"SGPA: {student1.SGPA()}")
  101.  
  102. student1.printInfo()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement