- #1
mathmari
Gold Member
MHB
- 5,049
- 7
Hey! :giggle:
I found online the following code for a christmas tree in Python :
Could you explain to me why the "spaces" is at the beginning equal to "tree_height-1" ? Shouldn't it be the half of that? :unsure:
I found online the following code for a christmas tree in Python :
Code:
tree_height = input("Enter the tree height : ")
tree_height = int(tree_height)
spaces = tree_height-1
hashes = 1
stump_spaces = tree_height-1
while tree_height != 0 :
for i in range(spaces):
print(' ', end="")
for i in range(hashes):
print('#', end="")
print()
tree_height -= 1
spaces -= 1
hashes += 2
for i in range(stump_spaces):
print(' ', end="")
print('#',end="")
Could you explain to me why the "spaces" is at the beginning equal to "tree_height-1" ? Shouldn't it be the half of that? :unsure: