PYTHON LAB MANUAL : Part I

1. Develop a program to read the student details like Name, USN, and Marks in three subjects. Display the student details, total marks and percentage with suitable messages.

Source Code :

class Student:
    marks = []
    def getData(self, name, USN,max_marks, m1, m2, m3):
        Student.name = name
        Student.USN = USN
        Student.max_marks = max_marks
        Student.marks.append(m1)
        Student.marks.append(m2)
        Student.marks.append(m3)
        
    def displayData(self):
        print ("Name is: ", Student.name)
        print ("USN is: ", Student.USN)
        print ("Marks are: ", Student.marks)
        print ("Total Marks is: ", self.total())
        print ("Average Marks is: ", self.average())
        print ("Percentage Marks is: ", self.percentage())
    
    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)
    
    def percentage(self):
        return ((self.average()/Student.max_marks)*100)

name = input("Enter the name: ")
usn = int (input("Enter the usn: "))
max_marks = int (input("Enter the max_marks (25/50/100/Any max):"))
m1 = int (input("Enter the marks in the first subject out of {0}:".format(max_marks)))
m2 = int (input("Enter the marks in the second subject out of {0}:".format(max_marks)))
m3 = int (input("Enter the marks in the third subject out of {0}:".format(max_marks)))

s1 = Student()
s1.getData(name, usn,max_marks,m1, m2, m3)
s1.displayData()

Sample Output

Enter the name: Thyagu
Enter the usn: 12345
Enter the max_marks (25/50/100/Any max):25
Enter the marks in the first subject out of 25:23
Enter the marks in the second subject out of 25:21
Enter the marks in the third subject out of 25:21
Name is:  Thyagu
USN is:  12345
Marks are:  [23, 21, 21]
Total Marks is:  65
Average Marks is:  21.666666666666668
Percentage Marks is:  86.66666666666667