Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Debugging / Error Handling, Data Structures and Data Search

Table of Contents


Assignment

This unit also inlcuded an assignment. We were tasked to present a system design proposal for a driverless car.

View the assignment and its reflection here


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:
    • items()
    • keys()
    • values()
class Car():
  def __init__(self, make, model, year, engine_type, engine_size, fuel_type):
    self.car_data = {
      "make": make,
      "model": model,
      "year": year,
      "engine": {
        "type": engine_type,
        "size": engine_size,
        "fuel": fuel_type
      }
    }

  def get_car_items(self):
    return self.car_data.items()

  def get_car_keys(self):
    return self.car_data.keys()

  def get_car_values(self):
    return self.car_data.values()


Tesla = Car("Tesla", "Model S", 2019, "electric", 100, "electricity")
print(Tesla.get_car_items())
print(Tesla.get_car_keys())
print(Tesla.get_car_values())


Reflection

In this unit we covered a lot of ground. We learned about debugging and error handling, utilizing tools such as linters to help us write clean code and this unit also included the first assignment of the module. We also touched on search algorithms.

Knowing how to debug and handle errors is an important skill for any developer. It is important to be able to identify and fix errors in code. This can be done using a debugger. A debugger is a tool that can be used to step through code and identify where errors are occurring.

Python offers various tools for linting and formatting code. These tools help to ensure that code is written in a consistent manner and that it is readable. Linters can also help to identify potential errors in code. A common linter for Python is Pylint. Other alternatives include Flake8 and Black.

In my opinion, I would advise developers (especially junior developers) to try out various linters and formatters and see which one works best for them. Some linters can be quite aggressive and can flag up a lot of errors and this can be/get quite overwhelming.

Resources