Student Result Analysis Using Class in Python


Analyse Student Result Using Class where all methods are defined inside the class Definition

 class StudentResult:

    def calculate_total(self, s1_marks, s2_marks):

        totals = s1_marks + s2_marks

        return totals

    

    def calculate_percentage(self, s1_marks, s2_marks):

        total_marks = self.calculate_total(s1_marks, s2_marks)

        return (total_marks / 200) * 100

    

    def calculate_grade(self, s1_marks, s2_marks):

        percentage = self.calculate_percentage(s1_marks, s2_marks)

        if percentage >= 90:

            return 'A+'

        elif 80 <= percentage < 90:

            return 'A'

        elif 70 <= percentage < 80:

            return 'B+'

        elif 60 <= percentage < 70:

            return 'B'

        elif 50 <= percentage < 60:

            return 'C'

        elif 40 <= percentage < 50:

            return 'D'

        else:

            return 'Fail'


# Example usage with user input

student = StudentResult()


# Input marks for s1 and s2

s1_marks = int(input("Enter marks for subject 1: "))

s2_marks = int(input("Enter marks for subject 2: "))


# Calculate totals, percentage, and grade

totals = student.calculate_total(s1_marks, s2_marks)

percentage = student.calculate_percentage(s1_marks, s2_marks)

grade = student.calculate_grade(s1_marks, s2_marks)


# Display the result

print("Total Marks:", totals)

print("Percentage:", percentage)

print("Grade:", grade)


x

टिप्पणी पोस्ट करा

0 टिप्पण्या