\(\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 calledprintTreethat will print the names & ids of the detectors contained within itWrite a class called
Componentthat stores a single name attributeReorganise the
Instrument&Detectorclasses to useComponentas a super class and share its name attributeCheck the
printTreemethod still functions correctly.
Once finished check your answer with the provided Exercise 1 Solutions