Control Flow: The for Loops

Triangle

Drawing a triangular shape on the console output using for loops.


*
**
***
****
*****
******
*******
********
*********
**********

Code:

def draw_triangle(height):

    for h in range(height):
        for i in range(h+1):
            print("*", end='')

        print()


triangle_height = 10

draw_triangle(triangle_height)

Practice: Try drawing with a single for loop.