# Tutorial 4 Problem 3 # Write a recursive function printPattern(seed, depth) such that when we call it as # follows: printPattern('a', 8), it produces the following output: # aaaaaaaa # bbbbbbb # cccccc # ddddd # eeee # fff # gg # h # h # gg # fff # eeee # ddddd # cccccc # bbbbbbb # aaaaaaaa # Hint: Feel free to use the built-in functions ord('a'), which produces 97, and chr(97) # which produces 'a'. Feel free to combine them. # Why is the first parameter called ‘seed’? # Answer: because it is used as the "seed", i.e., as the first value of the print pattern. # Why is the second parameter called ‘depth’? # Answer: because it is the "depth" of the recursion, i.e., the number of times the recursive # function is called (# of stackframes) def printPattern(seed, depth): if depth != 0: print(seed*depth) printPattern(chr(ord(seed)+1), depth-1) print(seed*depth) return # Main printPattern('a', 8) print() printPattern('c', 10)