Here is something I've tried:
def print_line(x, y, z):
for row in range(0, y + 1): # row
reverse = False
pattern_length = (y*x) - x
for col in range(-x + 1, z): # column
if reverse:
for a in range(0,x):
# print("%d-%d "%(col, row), end='')
if (((col + a) % pattern_length) == x * (y - row -1)):
# print('*** ', end="")
print("#", end="")
else:
# print("%d-%d "%(col, row), end='')
print(" ", end="")
else:
for a in range(0,x):
if ((col + a) % pattern_length== row*x):
print('#', end="")
else:
print(" ", end='')
if (col + x) % pattern_length == 0:
# print('|', end="") # uncomment this line to see the separation line
reverse = not reverse
print()
outputs:
>>> print_line(2, 4, 20)
## ##
## ## ##
## ## ## ##
## ##
>>> print_line(2, 6, 40)
## ## ##
## ## ## ##
## ## ## ##
## ## ## ##
## ## ## ##
## ##
>>> print_line(3, 5, 40)
# # # # # #
# # # # # # # # #
# # # # # # # # # #
# # # # # # # # # # # #
# # # # # #
The way it works is that, we first need to divide the board into sections (those we print the forward slash pattern, and those with the backward) - we are using reverse
variable to represent that. and then for every cell in the backward slash section we check whether we the row number and row*x
number match as well as whether it is to the right of a cell with the #
printed in and within x
units distance, if so we print #
there as well. The forward slash section follows similar logic but we check the column number against x * (y - row -1)
instead (the reverse).
Although the output may not be the exact match of your desired output, this may help you get started and get some ideas.