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

Exercise 2

The aim of this exercise is to write a small Python algorithm that is able to print to the Messages Box the first n numbers of the Fibonacci series. The series starts with 0, 1 and then the next term is the sum of the two previous terms.

The algorithm should:

  1. Define a property that sets the maximum number of terms to print. Single letters are not considered good property names so a good name would be something like NTerms

  2. The property should have documentation that shows in the GUI describing what it is used for.

  3. Validate that NTerms property is greater or equal to 0 when set in the GUI.

  4. The log message for the value of each term should be at notice level and in the format: “Term 1 in the Fibonacci series is: 0”

  5. Add a log message at the debug level that prints the value of the NTerms property after it has been retrieved.

As an additional exercise in understanding errors:

  1. On execution, check that the value of NTerms is less than or equal to 1000. If it is not then raise a RuntimeError.

Once finished check your answer with the provided Exercise 2 Solutions