Exercise 2: Using a Module
Learn to define and include a module in different classes.
We'll cover the following...
We'll cover the following...
Problem statement
Define two classes, Student and Teacher, by including a module called Formatter in both classes.
Task 1:
You’re required to:
- Populate the class attributes of
StudentandTeacherthrough theinitialize()method.
- Define attribute readers for these attributes.
Each of these classes has the attributes:
first_namelast_namephone_no
And an instance method:
print_info: This method uses the methods defined in theFormattermodule to print the name and phone number information.
Task 2
The Formatter module includes the following methods:
-
format_name: This method capitalizes only the first letters offirst_nameandlast_nameand combines the two. -
format_phone: This method takes a phone number stored as a string and removes its hyphens.
Try it yourself
# Start your code here