\(\renewcommand\AA{\unicode{x212B}}\)

Exercise 1ΒΆ

The aim of this exercise is to familiarise you with the use of objects within Python.

  1. Write a Detector class contains two attributes: id and name. The attributes should be able to be set by a call like: Detector(1, "bank1_1").
  2. Write an Instrument class with two attributes: name and list of detectors. These attributes should also be able to be set by a call like: Instrument('MyInst', dets).
  3. Add a method to the Instrument class called printTree that will print the names & ids of the detectors contained within it
  4. Write a class called Component that stores a single name attribute
  5. Reorganise the Instrument & Detector classes to use Component as a super class and share its name attribute
  6. Check the printTree method still functions correctly.

Once finished check your answer with the provided Exercise 1 Solutions