Develop a Python program. Define a class in Python and use it to create an object and display its components. Define a Student class with the following components (attributes):  Name  Student number  Number of courses current semester

Respuesta :

Answer:

  1. class Student:
  2.    def __init__(self, Name, Student_Num, NumCourse):
  3.        self.Name = Name  
  4.        self.Student_Num = Student_Num  
  5.        self.NumCourse = NumCourse  
  6. s1 = Student("Kelly", 12345, 4)
  7. print(s1.Name)
  8. print(s1.Student_Num)
  9. print(s1.NumCourse)

Explanation:

Firstly, use the keyword "class" to create a Student class.

Next, create a class constructor (__init__) that takes input for student name, student number and number of course (Line 2) and assign the input to the three class attributes (Line 3-5). All the three class attributes are preceded with keyword self.

Next, create a student object (Line 7) and at last print all the attributes (Line 8-10).