Solution 1

def create_box(height, width, char):
    result = ''
    for h in range(height):
        line = ''
        for w in range(width):
            line += char
        result += (line + '\n')
    return result

Create ASCII Box

Write a function create_box that takes three inputs: height (rows), width (columns), and a character char and creates a height × width box using the character char.

For this exercise, it's recommended to use a nested for-loop. There are other ways of solving it (which might be a good starting point), but try reaching the nested for-loop solution.

>>> create_box(3, 4, '*')
'****
 ****
 ****'
>>> create_box(2, 2, '@')
'@@
 @@'

IMPORTANT: You need to return your box, not just print it.

Test Cases

test a 1x1 box - Run Test

box_1x1_expected = """
@
""".lstrip()

def test_a_1x1_box():
    assert create_box(1, 1, '@') == box_1x1_expected

test a 5x8 box - Run Test

box_5x8_expected = """
xxxxxxxx
xxxxxxxx
xxxxxxxx
xxxxxxxx
xxxxxxxx
""".lstrip()

def test_a_5x8_box():
    assert create_box(5, 8, 'x') == box_5x8_expected

test a 3x4 box - Run Test

box_3x4_expected = """
****
****
****
""".lstrip()

def test_a_3x4_box():
    assert create_box(3, 4, '*') == box_3x4_expected
def create_box(height, width, char): pass