# You must make sure to run all cells in sequence using shift + enter or you might encounter errors
from pykubegrader.initialize import initialize_assignment
responses = initialize_assignment("16_GMT_q", "week_7", "readings", assignment_points = 20.0, assignment_tag = 'week7-readings')
# Initialize Otter
import otter
grader = otter.Notebook("16_GMT_q.ipynb")
โ Multiple Inheritance in Python: The Rolex GMT Master#
The Rolex GMT-Master is one of the most iconic watches ever created, designed for pilots and travelers who needed to track multiple time zones. The watch combines precise movement, durability, and aesthetic elegance.
Similarly, in Python, multiple inheritance allows a class to combine features from multiple parent classes, just like the GMT-Master blends aviation functionality with luxury craftsmanship.
Letโs explore how multiple inheritance enables us to design complex and versatile class structuresโjust like Rolex engineers do when crafting legendary watches.
# Run this block of code by pressing Shift + Enter to display the question
from questions._16_GMT_q import Question1
Question1().show()
# Run this block of code by pressing Shift + Enter to display the question
from questions._16_GMT_q import Question2
Question2().show()
# Run this block of code by pressing Shift + Enter to display the question
from questions._16_GMT_q import Question3
Question3().show()
Question 1 (Points: 12.0): โ Free Response: Implement Multiple Inheritance for a Rolex GMT Watch#
Design a Python class structure that models a Rolex GMT-Master watch using multiple inheritance:
Create a base class
Timekeeping
with:A method
show_time()
that returns"Showing local time."
Create another base class
GMTFunctionality
with:A method
show_gmt()
that returns"Showing GMT time."
Create a subclass
RolexGMT
that:Inherits from both
Timekeeping
andGMTFunctionality
.Overrides
show_time()
to include both local and GMT time.
Example Usage#
watch = RolexGMT()
print(watch.show_time())
print(watch.show_gmt())
Expected Output:
Local Time: Showing local time.
GMT Time: Showing GMT time.
...
# Example usage
watch = RolexGMT()
print(watch.show_time())
print(watch.show_gmt())
grader.check("Rolex-GMT-Multiple-Inheritance")
Submitting Assignment#
Please run the following block of code using shift + enter
to submit your assignment, you should see your score.
from pykubegrader.submit.submit_assignment import submit_assignment
submit_assignment("week7-readings", "16_GMT_q")