Slightly embarrassed to be posting this as I could succesfully complete mario(less) in pset1 but apparently cannot replicate it in Python. My code is as follows:
h = int(input("h: ")) # get height
while h < 1 or h > 8:
h = int(input("h: ")) # reprompt if outside range
for row in range(0, h, 1):
for space in range(0, h-row-1, 1):
print(" ", end="")
for column in range(0, row+1, 1):
print("#", end="")
print("")
I believe that the issue is in the spacing part. If I remove the spacing part (the for loop and the print " " line) then I successfully produce a left-aligned pyramid. But I cannot get it to become right-aligned using proper spacing. This was my C code i was trying to replicate:
#include <stdio.h>
#include <cs50.h>
int main(void)
{
int height, row, column, space;
do
{
height = get_int("How high do you want your pyramid: ");
}
while (height < 1 || height > 80);
for (row = 0; row < height; row++)
{
for (space = 0; space < height - row - 1; space++)
{
printf(" ");
}
for (column = 0; column <= row; column++)
{
printf("#");
}
printf("\n");
}
}
Any help is appreciated! And please, if you're explaining, err on the side of over-explaining and patronising because I am a rank beginner. Thank you!