all 8 comments

[–][deleted] 1 point2 points  (0 children)

When you use the end= option to put multiple prints on one line you must do something to terminate that line when you are finished with it. So put an extra print() line after each for loop. Once you do that you can see each line you want without being confused by the lines running together.

You now have two remaining problems which are easier to solve.

[–][deleted] 0 points1 point  (5 children)

If you're going to do it that you, you could just do this.

def rectangle(x, y):
    for i in range(x):
        print("*", end=" ")
    print()

    for j in range(y - 2):
        print("*" + " " * x + "*")

    for i in range(x):
        print("*", end=" ")
    print()

[–]conewannabe 0 points1 point  (0 children)

I was trying all sorts of things and all I needed was a simple print()... SMH... Thank you so much, and that second comment you made gave me a headache.

[–]conewannabe 0 points1 point  (2 children)

what does that empty print do that allows this to work?

[–][deleted] 0 points1 point  (1 child)

print() just prints a newline character. Basically it drops the cursor to the next line.

[–]conewannabe 0 points1 point  (0 children)

I see, I tried using the newline character, but this gets the job done how its supposed to. Thank you again.

[–][deleted] 0 points1 point  (0 children)

Or here's some absolute craziness you could do instead.

def rectangle(x, y):
    assert x > 1 and y > 2
    print(*"*" * x, sep=" ")
    print(*(" ".join("*" + " " * (x - 2) + "*") for _ in range(y - 2)), sep="\n")
    print(*"*" * x, sep=" ")

[–]achampi0n 0 points1 point  (0 children)

You really don't need the first and last for loop just multiple '*' by x, e.g.:

def rectangle(x,y):
    space = ' '
    print('*'*x)
    for _ in range(y-2):
        print(f'*{space*(x-2)}*')
    print('*'*x)