Skip to content

Commit ff339e4

Browse files
authored
Add teacher_class to solution
1 parent 1814edf commit ff339e4

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+

0 commit comments

Comments
 (0)