# 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("14_toyota_accelerator_q", "week_7", "readings", assignment_points = 19.0, assignment_tag = 'week7-readings')
# Initialize Otter
import otter
grader = otter.Notebook("14_toyota_accelerator_q.ipynb")
๐ Abstraction in Python: The Single Bit Flip That Killed Toyotaโs Accelerator#

In 2009, a major recall of Toyota vehicles was triggered by sudden unintended acceleration incidents. Investigations revealed that a single bit flip in memory could cause a stuck accelerator, leading to catastrophic failures.
This was due to software complexityโToyotaโs acceleration control system had millions of lines of code, with poor abstraction making debugging nearly impossible.
In Python, abstraction helps us hide complexity by defining base classes and abstract methods, ensuring only essential details are exposed.
Letโs explore how abstraction in Python can help us design safer, more manageable software systemsโjust as Toyota engineers should have done.
# Run this block of code by pressing Shift + Enter to display the question
from questions._14_toyota_accelerator_q import Question1
Question1().show()
# Run this block of code by pressing Shift + Enter to display the question
from questions._14_toyota_accelerator_q import Question2
Question2().show()
# Run this block of code by pressing Shift + Enter to display the question
from questions._14_toyota_accelerator_q import Question3
Question3().show()
Question 1 (Points: 11.0): โ๏ธ Free Response: Implement Abstraction for a Safer Accelerator System#
Implement a safe accelerator control system using abstraction:
Create an abstract class
AcceleratorControlwith:An abstract method
apply_brakes().An abstract method
override_acceleration().
Note: since we donโt want to implement these methods in the base class, we use the @abstractmethod decorator, and pass as a placeholder.
Create a subclass
ToyotaAcceleratorthat:Implements
apply_brakes()by printing"Brakes applied!".Implements
override_acceleration()by printing"Acceleration override engaged!".
Example Usage#
t = ToyotaAccelerator()
t.apply_brakes()
t.override_acceleration()
Expected Output:
Brakes applied!
Acceleration override engaged!
...
# Example usage
t = ToyotaAccelerator()
t.apply_brakes()
t.override_acceleration()
grader.check("Toyota-Abstraction-Class")
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", "14_toyota_accelerator_q")