I have tried rearranging the code around and I am very close to figuring this out but in my True statement the results are close to aliging correctly but I can't figure it out. This homework assignment requires that the rows alternate with a space if True but if False they must form a square.
My code:
def get_brick_pattern(max_rows=1, max_cols=1, running_bond=True or False):
brick = ""
result = ""
columns = max_cols
rows = max_rows
if running_bond is True:
for rows in range(max_rows):
for columns in range(max_cols):
if (rows) % 2 == 0:
result += brick
else:
result += " " + brick
result += "\n"
return result
elif running_bond is False:
for rows in range(1, max_rows+1):
for columns in range(1, max_cols+1):
result += brick
result += "\n"
return result
print(get_brick_pattern(3, 6, True))---for testing
The results are supposed look like just as an example:
My current output for the True statment looks like this:
You shouldn't add a space before each brick in the inner loop, just at the beginning of the line. Move the
if rows % 2 == 0:check to the outer loop.Then you don't need the inner loop at all, since you can use
*to repeat a string N times.