I wanna replace 1 to * and 0 to ” to make a tree.
I did this with for-loop.
picture = [
[0,0,0,1,0,0,0],
[0,0,1,1,1,0,0],
[0,1,1,1,1,1,0],
[1,1,1,1,1,1,1],
[0,0,0,1,0,0,0],
[0,0,0,1,0,0,0]
]
i = 0
while i < len(picture):
j = 0
while j < len(picture[i]):
if picture[i][j] == 0:
print('', end='')
else:
print('*', end='')
i += 1
>Solution :
try this.
picture = [
[0,0,0,1,0,0,0],
[0,0,1,1,1,0,0],
[0,1,1,1,1,1,0],
[1,1,1,1,1,1,1],
[0,0,0,1,0,0,0],
[0,0,0,1,0,0,0]
]
i = 0
while i < len(picture):
j = 0
while j < len(picture[i]):
if picture[i][j] == 0:
print('', end='')
else:
print('*', end='')
j += 1
print()
i += 1
If you want this output
*
***
*****
*******
*
*