\(\renewcommand\AA{\unicode{x212B}}\)
Exercise 1ΒΆ
The aim of this exercise is to familiarise you with the use of objects within Python.
- Write a - Detectorclass contains two attributes: id and name. The attributes should be able to be set by a call like:- Detector(1, "bank1_1").
- 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).
- Add a method to the - Instrumentclass called- printTreethat will print the names & ids of the detectors contained within it
- Write a class called - Componentthat stores a single name attribute
- Reorganise the - Instrument&- Detectorclasses to use- Componentas a super class and share its name attribute
- Check the - printTreemethod still functions correctly.
Once finished check your answer with the provided Exercise 1 Solutions