S
S
Salim2021-09-11 18:15:23
Python
Salim, 2021-09-11 18:15:23

How to draw a triangle?

How to draw a triangle so that the inside of the triangle is empty.

so it turns out to do but it turns out complete

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

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
rusyska55011, 2021-09-11
@rusyska55011

height = 10
for row_level in range(height):
    string = ''
    for left_step in range(height - row_level):
        string += ' '
    string += '*'

    for right_step in range(row_level * 2):
        string += ' '
    print(string + '*')

else:
    string = ''
    for i in range(height * 2 + 2):
        string += '*'
    print(string)

D
Developer, 2021-09-11
@samodum

Output * is necessary only for the start and end index in loops

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question