File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
2_intermediate/chapter12/solutions Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ # Create a class called Teacher. Add 3 variables to this
2+ # class: Name, Age, and an array of Student classes from student_class.
3+ # The user can input these 3 variables. Add 2 Methods to the class: A
4+ # displayClass method that prints out the names of all the students.
5+ # A graduate method that increments the age of all of his/her students by 1.
6+ # Then prints out all the ages.
7+
8+ # Student class implemented below. Teacher class uses it.
9+
10+ class Student :
11+
12+ def __init__ (self , name , age ):
13+ self .name = name
14+ self .age = age
15+
16+ def raiseHand (self ):
17+ print (self .name + " is now raising their hand." )
18+
19+ def growOlder (self ):
20+ self .age += 1
21+
22+ class Teacher :
23+
24+ def __init__ (self , name , age , students ):
25+ self .name = name
26+ self .age = age
27+ self .students = students
28+
29+ def displayClass (self ):
30+ for student in self .students :
31+ print (student .name )
32+
33+ def graduate (self ):
34+ for student in self .students :
35+ student .age += 1
36+ print (student .age )
37+
You can’t perform that action at this time.
0 commit comments