0

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:
        break
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="")
    print()

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

the 4x4 pyramid

What mistake did I make here?

1 Answer 1

0
range(height)

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.

2
  • In other words, each line seems to be printing the correct number of spaces but is short one hash mark.
    – Cliff B
    Commented Nov 20, 2020 at 22:05
  • @Cliff Sorry, but I didn't quite get it. I literally just used spaces...
    – nmn
    Commented 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 .