Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(Python 3.5, short and simple codes will suffice) 1. Write a recursive function named productOfOdds that accepts a tuple containing integer values and returns the

(Python 3.5, short and simple codes will suffice)

1. Write a recursive function named productOfOdds that accepts a tuple containing integer values and returns the product of the odd-valued elements in the tuple. You may assume the tuple has at least one odd-valued element. The product of the odd-valued elements may be calculated as follows:

If the tuple has a single element and it is odd, return the value of that element; otherwise return 1

Otherwise, if the first element of the tuple is odd, return the product of that element and the result of finding the product of hte odd elements of the rest of the tuple. If the first element is not odd, simply return the result of of finding the product of the odd elements of the rest of the tuple.

_________________________________________________________________________________________________

2. Write the definition of a function named printStarBucks that receives one parameter containing a non-negative integer value, n, and prints a line consisting of n asterisks followed by n dollar signs. So if the function received 5, it would print: *****$$$$$ And if it received 3, it would print: ***$$$ The function must not use a loop of any kind

_________________________________________________________

3. Write a function called fact that recursively calculates the factorial value of its parameter, which is an integer value.

_____________________________________________________________________________

4. The "odd/even factorial" of a positive integer n is represented as n and is defined non-recursively as: (n)(n-2)(n-4)...(4)(2) if n is even and (n)(n-2)(n-4)...(5)(3)(1) if n is odd. For example, the even factorial of 7 equals 7*5*3*1 or 105, and the even factorial of 6 equals 6*4*2 or 48. Come up with a recursive definition for the odd/even factorials and use it to write a function called oddevenfact that recursively calcules that odd/even factorial value of its single parameter, which contains an integer value.

______________________________________________________

5. Two non-negative integers x and y are equal if either:

Both are 0, or

x-1 and y-1 are equal

Write a function named equals that recursively determines whether two parameters (both containing integer values) are equal and returns True or False.

____________________________________________________________________________

6. Assume the availability of a function named printStars that can be passed one argument, an integer value n, which prints n asterisks. Write a function named printTriangle that receives an integer value as an argument and prints a triangle of asterisks as follows: first a line with 1 asterisk, then a line with 2 asterisks, then a line with 3 asterisks, and so on until it prints a line of n asterisks, at which point it stops. For example, if the function received 5, it would print: * ** *** **** ***** The function must not use a loop of any kind. The function should invoke printStarsto accomplish the task of printing a single line.

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

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions