Answered step by step
Verified Expert Solution
Link Copied!

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.

image text in transcribed

Here are the Annoying Requirements:

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

3rd Edition

978-1119907466

More Books

Students also viewed these Databases questions

Question

Compare and contrast families and family roles across cultures

Answered: 1 week ago

Question

Have roles been defined and assigned?

Answered: 1 week ago