Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please write this function in python. Do not use loops. Here are the Annoying Requirements: annoying_fibonacci_sequence(n) In annoying_recursion_part2.py, write a function, annoying_fibonacci_sequence(n), which returns the
Please write this function in python.
Do not use loops.
Here are the Annoying Requirements:
annoying_fibonacci_sequence(n) In annoying_recursion_part2.py, write a function, annoying_fibonacci_sequence(n), which returns the first n numbers in the Fibonacci sequence. In the previous project, you wrote a recursive function which returned a single integer, which was the n-th Fibonacci number. This time, return an array of length n, which contains that many of the Fibonacci numbers. Thus, if n = 0, return an empty array; if n = 3 return [0,1,1]; if n = 6, return [0,1,1,2,3,5). This function must obey the Annoying Requirements. (Remebmer, the An- noying Requirements don't allow you to use helper functions - so it's not legal to call a function to generate each Fibonacci number! But remember the defi- nition of Fibonacci numbers - if you had an array with the first n-1 Fibonacci numbers, what simple trick could you use to calculate the n-th one?) 2.1 4 Base Cases Every annoying" function must have special cases for the values 0,1,2,3. For each of these values, you must implement it as a base case - that is, simply return or print) the answer - without any recursion at all. 2.2 3 Hard-Coded, but Recursive Cases Every "annoying" function must also have special cases for the values 4,5,6. These must be implemented recursively, but you must hard-code what you recursively call. That is, don't use the value n in those cases at all (except to figure out that you are in that case). So, for instance, the factorial function might include this snippet: if n == 5: return 5 * annoying_factorial (4) 2.3 The General-Purpose Case Finally, every "annoying" function must have a general case. (This is what would be the body of the recursive in a more typical solution. This general case: Must not execute except for n > 7. (But it must work properly for all such large values!) Must recurseStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started