Question
PYTHON. That is just the way the pattern is 1.Write a recursive function printPattern() that will generate the following patterns. Note that the first argument
PYTHON. That is just the way the pattern is
1.Write a recursive function printPattern() that will generate the following patterns. Note that the first argument is always a power of 2 and is the max number of stars appearing in the middle row. The second argument (which defaults to 0) is the number of spaces to put before each patterns rows of stars.
>>> printPattern(8,0)
*
**
*
****
*
**
*
********
*
**
*
****
*
**
*
>>> printPattern(4,2)
*
**
*
****
*
**
*
>>> printPattern(4)
*
**
*
****
*
**
*
- Write a recursive function gcd(m,n) that returns the greatest common divisor of a pair of numbers. The gcd of m and n is the largest number that divides both m and n. If one of the numbers is 0, then the gcd is the other number. If m is greater than or equal to n, then the gcd of m and n is the same as the gcd of n and m-n. If n is greater than m, then the gcd is the same as the gcd of m and n-m.
>>> gcd(5,0)
5
>>> gcd(15,5)
5
>>> gcd(5,7)
1
>>> gcd(24,144)
24
>>> gcd(124,144)
4
>>>
- Write a recursive function f that generates the sequence 0,1,0.5,0.75,0.625,0.6875,0.65625,0.671875,0.6640625,0.66796875. The first two terms are 0 and 1, every other term is the average of the two previous.
>>> f(0)
0
>>> f(1)
1
>>> f(2)
0.5
>>> [ (i,f(i)) for i in range(10)]
[(0, 0), (1, 1), (2, 0.5), (3, 0.75), (4, 0.625), (5, 0.6875), (6, 0.65625), (7, 0.671875), (8, 0.6640625), (9, 0.66796875)]
>>>
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