Question
short python 3 question: no need for a long code just write the required code. 1) The elements of tuple can be initialized so that
short python 3 question: no need for a long code just write the required code.
1) The elements of tuple can be initialized so that tup[i] == i in a recursive fashion as follows:
- A tuple of size 0 is already initialized
- Otherwise:
- set the last element of the tuple to n-1 (where n is the number of elements in the tuple)
- initialize the portion of the tuple consisting of the first n-1 elements
Write a function named init that takes one argument, a tuple of the proper length, and returns an tuple initialized as described above.
2) 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.
3)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.
4) Write a function called fact that recursively calculates the factorial value of its parameter, which is an integer value.
5) 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.
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