728x90
반응형
class Product:
def __init__(self, name, price, quantity):
self.name = name
self.price = price
self.quantity = quantity
# 재고 업데이트 메서드
def update_quantity(self, amount):
self.quantity += amount
print(
f"{self.name} 재고가 {amount}만큼 {'증가' if amount > 0 else '감소'}했습니다. 현재 재고: {self.quantity}")
# 상품 정보 출력 메서드
def display_info(self):
print(f"상품명: {self.name}")
print(f"가격: {self.price}원")
print(f"재고: {self.quantity}개")
class Electronic(Product):
def __init__(self, name, price, quantity, warranty_period=12):
super().__init__(name, price, quantity)
self.warranty_period = warranty_period
def extend_warranty(self, month):
total_warranty = self.warranty_period + month
print(
f"보증 기간이 {self.warranty_period}개월 연장되었습니다. 현재 보증 기간: {total_warranty}")
def display_info(self):
super().display_info()
print(f"보증 기간: {self.warranty_period}")
class Food(Product):
def __init__(self, name, price, quantity, expiration_date):
super().__init__(name, price, quantity)
self.expiration_date = expiration_date
def is_expired(self, current_date):
if current_date > self.expiration_date:
print(f"{self.name}은 유통기한이 지났습니다. ")
else:
print(f"{self.name}은 유통기한이 지나지 않았습니다.")
def display_info(self):
super().display_info()
print(f"유통기한 : {self.expiration_date}")
e1 = Electronic("스마트TV", 150000, 5, 24)
e1.display_info()
e1.extend_warranty(12)
f1 = Food("사과", 3000, 50, "2023-12-29")
f1.display_info()
f1.is_expired("2024-11-28")
반응형
'하루코딩 > python 하루코딩' 카테고리의 다른 글
| [Python] 영타자 연습 (0) | 2024.12.06 |
|---|---|
| [Pythone] 날짜별 전력 사용량 조회 프로그램 (0) | 2024.11.29 |
| [Python] 날씨 분석 프로그래밍 함수화 (0) | 2024.11.27 |
| [Pythone] 함수 종합 프로그래밍 (날씨데이터 표시) (0) | 2024.11.27 |
| [Python] 지정된 범위 내에서 n에대한 배수 찾기 (0) | 2024.11.26 |