ibebak
ibebak

Reputation: 13

Making a hollow triangle in Python in flipped direction

This is my code:

n = int(input('Enter an integer number: '))
for rows in range(n):
    for columns in range (n): 
        if columns==0 or rows==(n-1) or columns==rows: 
            print('*', end='') 
        else:
            print(end=' ')
    print()

This works fine making a hollow right angle triangle, except that I want the right angle triangle's right angle to be on the right. This code has it on the left like this: ◺, but I need it on the right like this: ◿.

Upvotes: 1

Views: 1781

Answers (1)

Ray Toal
Ray Toal

Reputation: 88378

You're very close!

You just need to change the conditions in your if statement.

Instead of

columns==0

you want

columns==n-1

so that the vertical line is on the right. Then also instead of

columns==rows

which makes the diagonal go from upperleft to lower right, you want

columns==n-rows-1

so that it goes from upper right to lower left.

Upvotes: 1

Related Questions