Python_Programming_Week6
1. 1. After having completed the above Q1, then write a Python program “Lab6B.py” to complete the following: • Define a class Student with 3 data attributes: name, college, major o The class should have __init__ method for initiation of the above data attributes. o Define __str__ method, in this way, the object created from this class can be “printed out” giving the object information. (Hints: refer website at Define a sub-class GraduateStudent (that inherits class Student defined above) with 2 more data attributes: project, scholarship (which means that this subclass should have a total of 5 data attributes!). o The class should have __init__ method for initiation of the above data attributes. o Define __str__ method, in this way, the object created from this sub-class can be “printed out” giving the object information. o (Hints: there are quite a few examples shown in Q1 which will guide you through this subclass definition!) Define main() method/function: to create several instances of super/sub-classes, and print out the related information. o Use the following demo executions for your instance creation and testing. o Hints: given the above definitions, you may: ▪ Use “Student s1 = Student()” to create an instance ▪ Use “print(s1)” to “print out” the instance of s1! ▪ Similar with GraduateStudent instances
Written for
- Institution
- Python Programming
- Course
- Python Programming
Document information
- Uploaded on
- July 22, 2023
- Number of pages
- 3
- Written in
- 2022/2023
- Type
- Exam (elaborations)
- Contains
- Questions & answers
Subjects
-
pythonprogrammingweek6
Also available in package deal