Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 Overview In this project, we'll be continuing with a few more annoying problems - submit the annoying problems in a file named annoying recursion_part2.py

image text in transcribed
image text in transcribed
image text in transcribed
1 Overview In this project, we'll be continuing with a few more "annoying problems - submit the annoying problems in a file named annoying recursion_part2.py In addition, you will be writing a few functions that recurse over linked lists: submit these in a file named linked_list_recursion_part_2.py. Follow the same rules as the Short problem: "annoying" problems must obey the annoving rules: the linked list problems do not. But of course, the linked list problems must be recursive! Likewise, just like in the Short problem, loops and helper functions (including default arguments) are banned. 1.1 Loops Banned In every function in this project - whether "annoying or not- loops are banned! (You are allowed to use string/list multiplication, however.) 1.2 Helper Functions Banned In every function in this project - whether "annoying" or not - helper functions are banned. Every one of these functions can be completed with only a single. recursive function. (And you have to use exactly the parameters I require, or you won't pass the testcases.) Some of you may know about default arguments in Python (if not, that's OK) - these are banned as well! Default arguments are a cool feature - but they are basically just a way to write a helper function, so they aren't allowed in this project, either. 2 annoying-triangleNumbers(n) In annoying.recursion_part2.py . write a function, annoying_triangleNumbers(n). which returns the sum 1+2 +3... + 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 n+1) the formula That's nice - but we're not going to use it. Instead, you're going to write a function that calculates it recursively. This function must obey the Annoying Requirements 2 1 3 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 1 which contains that many of the Fibonacci numbers. Thus, in 0 return an empty array: if n = 3 return [0,1,1). If n6, return [0,1,1,2,3,5) This function must obey the Annoying Requirements. (Remebmer, the An- muying 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?) 4 annoying-valley(n) In annoying recursion_part2.py write a functionif annoying_valley(n). which prints out the shape of a "valley": that is, a bunch of slashes, in the shape of a V pointing right. Do not return anything. This is the proper output for n = 5: This is the proper output for n. 2: IN This is the proper output for n 1 For 1-0, print out nothing at all This function must obey the Annoying Requirements. 2 For 20, print out nothing at all. This function must obey the Annoying Requirements. 2 4.1 Hints Did you notice that loops are banned in this project? How, then te yon going print out a whole bunch of periods in the various lines of your wey Remember string multiplication is allowed. Use it to create long te peated sequences es! Maybe you don't remember string multiplication? Try out this nippet of code and see what it does print("abc"-4)

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

Step: 3

blur-text-image

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

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions