Solution 1

def nested_pyramid(height, char):
    pyramid = ''
    for level in range(1, height + 1):
        row = ''
        for c in range(level):
            row += char

        row += '\n'
        pyramid += row

    return pyramid

Nested Pyramid

Write a function nested_pyramid that receives a number height and a character char and builds an ASCII Pyramid with them. Examples:

A pyramid with 5 levels:

nested_pyramid(5, '*')
*
**
***
****
*****

A pyramid with 3 levels:

nested_pyramid(3, '#')
#
##
###

Test Cases

test pyramid with 5 levels - Run Test

pyramid_5_expected = """
#
##
###
####
#####
""".lstrip()


def test_pyramid_with_5_levels():
    assert nested_pyramid(5, '#') == pyramid_5_expected

test pyramid with 3 levels - Run Test

pyramid_3_expected = """
@
@@
@@@
""".lstrip()


def test_pyramid_with_3_levels():
    assert nested_pyramid(3, '@') == pyramid_3_expected
def nested_pyramid(height, char): pass