import random


class colthes:

  def __init__(self, name="default", price=0, Best=False, Sold_out=False):
    # [공백 8칸] __init__ 블록 내부
    self.name = name
    self.price = price
    self.Best = Best
    self.Sold_out = Sold_out

    self.gen_code()

  def gen_code(self):  # [공백 4칸] 클래스 블록 내부
    tmp = int(random.random() * 10000)  # [공백 8칸]
    self.code = str(f"{tmp:04d}")

  def __str__(self):  # [공백 4칸] 클래스 블록 내부
    show = f"{self.name}\n{self.price:,}원\n"  # [공백 8칸]
    if self.Best:  # [공백 8칸]
      show = show + "Best\t"  # [공백 12칸]
    if self.Sold_out:  # [공백 8칸]
      show = show + "Sold_out"  # [공백 12칸]

    return show  # [공백 8칸]


# --- 클래스 외부 실행 코드 (들여쓰기 0칸, 맨 앞에 작성) ---
pd1 = colthes("스카프 원피스", 30880, True)

print(pd1)  # 상품 정보 출력
print(f"생성된 코드는: {pd1.code}")  # 생성된 4자리 코드 출력
       

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: