logo

Crowdly

Write a function named generate_magic_sequence that has two parameters, star...

✅ Перевірена відповідь на це питання доступна нижче. Наші рішення, перевірені спільнотою, допомагають краще зрозуміти матеріал.

Write a function named generate_magic_sequence that has two parameters, start, max.

The function should:

  1. Validate the provided parameter values as instructed below

  2. Generate the sequence using the algorithm below

  3. “Return” the generated sequence (do not just “print” it!)

You will need to do some validation on the parameter values provided:

  • A valid start value must be a int.

  • A valid max value must be an float.

  • A valid max value must be greater than or equal to the start value.

If any of the parameters are invalid, the function should return an empty list (i.e. []). You should not assume that the datatype provided is correct (i.e. a float value provided as a string should be accepted).

Your program should not crash or emit unhandled errors.

Algorithm

  1. Generate a sequence of numbers following the rules below:

    1. The first value in the sequence is the value in start.

    2. Each subsequent value is calculated by incrementing the last value added to the sequence by 2 (this is called ), then applying the formula sqrt() and rounding the value to two decimal places.

    3. Continue step ii while the value is less than or equal to the max value.

    4. The last value added to the sequence must be less than or equal to the max value.

  2. Return the sequence as a list.

Більше питань подібних до цього

Хочете миттєвий доступ до всіх перевірених відповідей на lms.monashcollege.edu.au?

Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!