class Shape:
def __init__(self, level):
self._level = level
def show(self):
pass
class Pyramid(Shape):
def show(self):
for i in range(1, self._level + 1):
print(' ' * (self._level - i) + '*' * (2 * i))
class RPyramid(Shape):
def show(self):
for i in range(1, self._level + 1):
print(' ' * (i - 1) + '*' * (2 * (self._level + 1 - i)))
class Square(Shape):
def show(self):
for _ in range(self._level):
print('*' * (2 * self._level))
class Rectangle(Shape):
def show(self):
for _ in range(self._level):
print(' ' * (self._level - 1) + '*' * 2)
def main():
level = int(input('請輸入層數(level),可產生4*level層星狀樹:'))
shapes = [Pyramid(level), Square(level), RPyramid(level), Rectangle(level)]
for shape in shapes:
shape.show()
if __name__ == "__main__":
main()