Want to write a function that outputs a pyramid of stars.
This function must be called with a print statement.
My solution results in None displayed.
def tree(n):
for i in range(n):
for j in range(n-i-1):
print(" ", end="")
for j in range(2*i+1):
print('*', end="")
print('\r')
print(tree(5))
*
***
*****
*******
*********
None
How do I get rid of the None?
I tried using a return statement with no success:
def tree(n):
for i in range(n):
a=((n - (i + 1)) * " " + ((2*i)+1) * '*')
return a
print(tree(5))
returns
*********
Is the return statement the right approach?
Calling the function without the print statement is not an option :)
Thanks.