I run through my code many times and didn't find anything wrong with it but the result printed out wasn't right:

from cs50 import get_int
while True:
    height = get_int("How high is the pyramid?\n")
    if height > 0 and height <= 8:
for row in range (height):
    for space in range (height - row):
        print(" ", end="")
    for col in range (row):
        print("#", end="")
    print("  ", end="")
    for col in range (row):
        print("#", end="")

When I let the height is 4 it printed out like this:

the 4x4 pyramid

What mistake did I make here?

1 Answer 1


For a value of 4 as shown, will give [0, 1, 2, 3]. So the first iteration will print (3 - 0) spaces and 0 blocks.

  • In other words, each line seems to be printing the correct number of spaces but is short one hash mark.
    – Cliff B
    Nov 20, 2020 at 22:05
  • @Cliff Sorry, but I didn't quite get it. I literally just used spaces...
    – nmn
    Nov 21, 2020 at 4:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .