Python program to store and display the student name and marks of a student
Problem Definition:
Write a python program to store and display the student name and marks of a student. Use the list to store the marks of a student in three subjects.
Video Tutorial
Program Description:
As said in the problem definition, first create a class named Students. The class Students have three methods, the init() method also known as a constructor, enterMarks, and display method.
init() method is called whenever an object of a class is created and used to initialize the attributes of the object. enterMarks() method is used to set the marks of students in three subjects and the display() method is used to display the student information.
In the main part of the program, we have created two objects and called the enterMarks and display methods using the objects of the Student class.
Source Code of Python program to read and display the student name and marks in three subjects
class students: count = 0 def __init__(self, name): self.name = name self.marks = [] students.count = students.count + 1 def enterMarks(self): for i in range(3): m = int(input("Enter the marks of %s in %d subject: "%(self.name, i+1))) self.marks.append(m) def display(self): print (self.name, "got ", self.marks) name = input("Enter the name of Student:") s1 = students(name) s1.enterMarks() s1.display() print ("") name = input("Enter the name of Student:") s2 = students(name) s2.enterMarks() s2.display() s2.displayCount()
Output:
Enter the name of Student: Mahesh Huddar
Enter the marks of Mahesh Huddar in 1 subject: 20
Enter the marks of Mahesh Huddar in 2 subject: 30
Enter the marks of Mahesh Huddar in 3 subject: 25
Mahesh Huddar got [20, 30, 25]
Enter the name of Student: Rahul
Enter the marks of Rahul in 1 subject: 30
Enter the marks of Rahul in 2 subject: 25
Enter the marks of Rahul in 3 subject: 29
Rahul got [30, 25, 29]
Summary:
This article discusses, how to write a Python program to read and display the student name and marks of a student. Subscribe to our YouTube channel for more videos and like the Facebook page for regular updates.