I'm a bit stuck in pset6 mario, hashes are printed in right number but not on the right side. I've tried to figure out myself but haven't come up with any correct solution so far so i'd really appreciate some help please.

here is the code i wrote so far: enter image description here

2 Answers 2


Either use inner for loops or the multiply syntax, but not both. So either

for j in range(n - i - 1):
    print(" ", end="")
for k in range(i + 2):
    print("#", end="")

or for example

print(" "*(n-i-1) + "#"*(i+2))

The way you're doing it, you're using the j loop the wrong way so it executes not at all, and have the i loop iterate exactly once where it should execute once per output line.

Also, you're placing everything in the while loop, while only the input request and input action should be repeated until valid input is provided.

  • Thanks for your detailed answer Blauelf, I overcomplicated it by adding those 2 for loops, only one turned out to be enough :)
    – Adel
    Sep 4, 2017 at 15:45

The j loop doesn't execute because of the way python range handles a negative step. From the python doc:

For a negative step, the contents of the range are still determined by the formula r[i] = start + step*i, but the constraints are i >= 0 and r[i] > stop.

j is always <= n + 2 (the "stop").

  • Thank you for your help and good resource, problem solved :)
    – Adel
    Sep 4, 2017 at 15:40

You must log in to answer this question.

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