0

I'm struggling to meet these specifications - "Be sure that the pyramid is aligned to the bottom-left corner of your terminal, and that there are no extra spaces at the end of each line."

Experimented with lstrip explained here: http://www.datasciencemadesimple.com/remove-spaces-in-python/

I've also tried using flush=True in the regular expression of the print function in my current code below explained here: https://www.geeksforgeeks.org/python-output-using-print-function/ and here: https://stackoverflow.com/questions/230751/how-to-flush-output-of-print-function

It's my second morning scouring the web and CS50 StackExchange for clues so any clues appreciated.

Thanks!

SiƓn

from cs50 import get_int

# Prompt user for height (1-8)
height = get_int("Height: ")

# Re-prompt if invalid
while height > 8 or height < 1:
    height = get_int("Height: ")

# Generate (with the help of print and one or more loops) the desired half-pyramid aligned to left-hand edge of terminal window
for x in range (0, height):
    print((height-1-x)*' ',(x+1)*'#',flush=True)

# NEED TO LEFT-ALIGN - USING LSTRIP? REGULAR EXPRESSIONS? F-STRINGS?
1

Don't make things complicated.

for x in range (height):
    print((height-x - 1)*' ' + (x+1)*'#')
| improve this answer | |

You must log in to answer this question.

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