Module 3
Object Oriented Programming
Unit 7
Debugging / Error Handling, Data Structures and Data Search
Learning Outcomes
- Apply Python tools to examine the quality of code.
- Implement data structures to store data.
- Implement a search algorithm to explore stored data.
e-Portfolio Activities
Create a nested dictionary of data on cars within a Car class. Extend the program to work with the dictionary by calling the following methods:
Code:
class Car:
def __init__(self):
self.car_data = {
"Electric": {
"Tesla": {"Model": "Model 3", "Year": 2023, "Price": 39999, "Color": "Red", "Fuel": "Electric"},
"Nissan": {"Model": "Leaf", "Year": 2022, "Price": 28999, "Color": "Blue", "Fuel": "Electric"},
},
"Hybrid": {
"Toyota": {"Model": "Prius", "Year": 2023, "Price": 25000, "Color": "Green", "Fuel": "Hybrid"},
"Honda": {"Model": "Insight", "Year": 2022, "Price": 23000, "Color": "White", "Fuel": "Hybrid"},
},
"Luxury": {
"BMW": {"Model": "X5", "Year": 2023, "Price": 60000, "Color": "Black", "Fuel": "Gasoline"},
"Audi": {"Model": "Q7", "Year": 2023, "Price": 62000, "Color": "Silver", "Fuel": "Diesel"},
}
}
def items(self):
for category, brands in self.car_data.items():
print(f"{category}: {brands}")
def keys(self):
for key in self.car_data.keys():
print(key)
def values(self):
for value in self.car_data.values():
print(value)
# Creating an object of the Car class
car = Car()
# Call object methods to view car data
print("All categories and brands:")
car.items()
print()
print("All categories:")
car.keys()
print()
print("All brands:")
car.values()
print()
System Design
- The assignment is divided into two parts: a design document for a humanoid robot, due in this unit, and its practical implementation, due in Unit 11. A 1,000-word design document was submitted, outlining the features, a general design, and UML diagrams. Link to the design document: here
Reflection
- The design document, developed in previous units, was refined and finalised. Commencing work early on the design document proved to be beneficial.