\(\renewcommand\AA{\unicode{x212B}}\)
Exercise 1ΒΆ
The aim of this exercise is to familiarise you with the use of objects within Python.
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")
.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
Instrument
class calledprintTree
that will print the names & ids of the detectors contained within itWrite a class called
Component
that stores a single name attributeReorganise the
Instrument
&Detector
classes to useComponent
as a super class and share its name attributeCheck the
printTree
method still functions correctly.
Once finished check your answer with the provided Exercise 1 Solutions