Computer Science, asked by Anonymous, 5 months ago

Create a class student having data members name, age, roll no, marks of 42 subjects, and total marks. Write a python program to read the details of n student ,find the total mark and display it.​

Answers

Answered by Anonymous
8

Answer:class Student:

  marks = []

  def getData(self, rn, name, m1, m2, m3):

      Student.rn = rn

      Student.name = name

      Student.marks.append(m1)

      Student.marks.append(m2)

      Student.marks.append(m3)

       

  def displayData(self):

      print ("Roll Number is: ", Student.rn)

      print ("Name is: ", Student.name)

      #print ("Marks in subject 1: ", Student.marks[0])

      #print ("Marks in subject 2: ", Student.marks[1])

      #print ("Marks in subject 3: ", Student.marks[2])

      print ("Marks are: ", Student.marks)

      print ("Total Marks are: ", self.total())

      print ("Average Marks are: ", self.average())

       

  def total(self):

      return (Student.marks[0] + Student.marks[1] +Student.marks[2])

   

  def average(self):

      return ((Student.marks[0] + Student.marks[1] +Student.marks[2])/3)

   

r = int (input("Enter the roll number: "))

name = input("Enter the name: ")

m1 = int (input("Enter the marks in first subject: "))

m2 = int (input("Enter the marks in second subject: "))

m3 = int (input("Enter the marks in third subject: "))

s1 = Student()

s1.getData(r, name, m1, m2, m3)

s1.displayData()

Output:

Enter the roll number: 10

Enter the name: Mahesh Huddar

Enter the marks in first subject: 20

Enter the marks in second subject: 30

Enter the marks in third subject: 25

Roll Number is:  10

Name is:  Mahesh Huddar

Marks are:  [20, 30, 25]

Total Marks are:  75

Average Marks are:  25.0

Explanation:

Similar questions