# Lab 7 def asteriskLine(len): ''' Non-recursive version of asteriskLine; provided in lab notes ''' return '*' * len # ------------------------------------ # Task 1 # ------------------------------------ def asteriskTriangle(len): ''' Prints inverted triangles composed of successilvely shorter lines of * ''' if len > 0: print asteriskLine(len) asteriskTriangle(len - 1) # Tests: #asteriskTriangle(5) # ------------------------------------ # Task 2 # ------------------------------------ def peaks(height, width): ''' Draws sideways peaks that contain 2 * height number of lines, with width initial number of asterisks per line ''' if height > 0: print '<' + asteriskLine(width) peaks(height-1, width+3) print asteriskLine(width) + '>' # Tests: # peaks(5,5) # ------------------------------------ # Bonus functions, provided FYI # ------------------------------------ def lineSymbol(len, symbol): ''' More robust version of asteriskLine ''' return symbol * len def lineSymbolV2(len,symbol): ''' Recursive version, just included for fun ''' if len == 1: return symbol else: partialLine = lineSymbol(len-1,symbol) return symbol + partialLine def triangleSymbol(len, sym): if len > 0: print lineSymbol(len, sym) triangleSymbol(len-1, sym) def asteriskLineV2(len): ''' Recursive version of asteriskLine, just included for fun ''' if len <= 0: return "" else: if len == 1: return "*" else: partialLine = asteriskLine(len-1) return "*" + partialLine