I'd like to create a single for loop using 2 variables, instead of a for loop and an external variable.
Is there a way to do something unpacking tuples with range?
Here is what I have:
space = height
for h in range(height):
# code using both h & space
Here is the code I'm trying to improve:
# Get positive integer between 1 - 8
while True:
height = int(input("Height: "))
if height > 0 and height < 9:
break
space = height # Control space count
# Build the pyramid
for h in range(height):
print(" " * (space - 1),"#" * (h + 1), end="")
print(" ", end="")
print( "#" * (h + 1), " " * (space - 1), end="")
space -= 1
print() # Get prompt on \n
spacedepends decreases ashincrease, why don't you just compute the offset, e.g. asheight - h -1?