I have to write a recursive function asterisk_triangle
which takes an integer and then returns an asterisk triangle consisting of that many lines.
As an example this is a 4 line asterisk triangle.
*
**
***
****
I have tried this function:
def asterix_triangle(depth):
rows = [ (depth-i)*' ' + i*2*'*' + '*' for i in range(depth-1) ]
for i in rows:
print i
And the following function:
def asterisk_triangle(rows=n):
pyramid_width = n * 2
for asterisks in range(1, pyramid_width, 2):
print("{0:^{1}}".format("*" * asterisks, pyramid_width))
And neither worked. I am supposed to make tests.py
to test the functions and I get errors for e.g
Traceback (most recent call last):
File "C:UsersakumaukpoDocumentsCISC 106LAB05lab05 _test.py", line 19, in <module>
from lab05 import *
File "C:UsersakumaukpoDocumentsCISC 106LAB05lab05.py", line 22
print i
^
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…