import turtle ## 상단에 추가

class Square:
    def __init__(self, t1, x, y, w):
        self.t = t1
        self.x = x
        self.y = y
        self.w = w
    def drawing(self):
        self.t.up()
        self.t.goto(self.x, self.y)
        self.t.down()
        a = 0
        while a < 4:
            a = a + 1
            self.t.fd(self.w)
            self.t.right(90)
        self.t.up()

class Pyramid:
    def __init__(self, shape, r, width):
        self.shape = shape
        self.row = r
        self.t = turtle.Turtle()
        self.width = width
    def drawing(self):
        i = 0
        while i < self.row:
            b = 0
            self.t.up()
            x = 50 - (i * self.width)
            y = 0 - (i * self.width)
            self.t.goto(x, y)
            self.t.down()
            while b < (i * 2) + 1:
                if self.shape == "사각형":
                    s = Square(self.t, x + (b * self.width), y, self.width)
                    s.drawing()
                elif self.shape == "삼각형":
                    pass
                elif self.shape == "오각형":
                    pass
                b = b + 1
            i = i + 1

num=5
width=30

p=Pyramid("사각형", num, width)
p.drawing()

import time
time.sleep(500)