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: In annoying_recursion_part2.py, write a function, annoying_triangleNumbers (n), which returns the
Please write this function in python.
Do not use loops.
Here are the Annoying Requirements:
In annoying_recursion_part2.py, write a function, annoying_triangleNumbers (n), which returns the sum 1+2+3...+n. Triangle numbers (https://en.wikipedia.org/wiki/Triangle_numbers) are calculated by summing up all of the values from 1 to n. Back in Algebra class, you probably learned that you can calculate that sum, quite easily, with the formula n(n+1) That's nice - but we're not going to use it. Instead, 2 you're going to write a function that calculates it recursively. This function must obey the Annoying Requirements. 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 recurse
Step 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