def drawRectangle(rows, cols):
for i in range(rows):
for j in range(cols):
print("*", end="")
print()
drawRectangle(3, 4)
print()
def drawChessBoard(n):
for i in range(n):
for j in range(n):
if((i+j) % 2 == 0):
print("W", end="")
else:
print("B", end="")
print()
drawChessBoard(8)
print()
def drawTriangle1(rows):
for i in range(rows):
for j in range(i+1):
print("*", end="")
print()
drawTriangle1(4)
print()
def drawTriangle2(rows):
for i in range(rows):
for j in range(rows-i-1):
print(" ", end="")
for k in range(i+1):
print("*", end="")
print()
drawTriangle2(4)
print()
# This one works the same way as the one above.
def drawTriangle2(rows):
for i in range(1, rows+1):
for j in range(1, rows+1):
if(i+j > rows):
print("*", end="")
else:
print(" ", end="")
print()
drawTriangle2(4)
print()
def drawO(n):
for i in range(-n,n+1):
for j in range(-n,n+1):
if(i**2 + j**2 <= n**2):
print("* ", end="")
else:
print(" ", end="")
print()
drawO(16)
# If height = 3, the shape should be:
# *
# ***
# *****
#
# If height = 4, the shape should be:
# *
# ***
# *****
# *******
#
# Here are a couple of test cases you can use:
assert(myTriangle(0) == "")
assert(myTriangle(3) == " * \n *** \n*****")