패스트캠퍼스 챌린지 13일차 (Python)
# 실습문제
# 1. 클래스 생성
# 아이템 클래스 생성
class Item:
def __init__(self, name, price, weight, isdropable):
self.name = name
self.price = price
self.weight = weight
self.isdropable = isdropable
def sale(self):
print(f"[{self.name}] 판매 가격은 [{self.price}] 입니다.")
def discard(self):
if self.isdropable:
print(f"[{self.name}] 버렸습니다.")
else:
print(f"[{self.name}] 버릴 수 없습니다.")
class WearableItem(Item):
def __init__(self, name, price, weight, isdropable, effect):
super().__init__(name, price, weight, isdropable)
self.effect = effect
def wear(self):
print(f"[{self.name}] 착용했습니다. [{self.effect}]")
class UsableItem(Item):
def __init__(self, name, price, weight, isdropable, effect):
super().__init__(name, price, weight, isdropable)
self.effect = effect
def use(self):
print(f"[{self.name}] 사용했습니다. [{self.effect}]")
# 인스턴스 생성
sword = WearableItem("이가닌자의검", 30000, 3.5, True, "체력 5000 증가, 마력 5000 증가")
sword.wear()
sword.sale()
sword.discard()
potion = UsableItem("신비한투명물약", 150000, 0.1, False, "투명효과 300초 지속")
potion.discard()
potion.sale()
potion.use()
패스트캠퍼스 [직장인 실무교육]
프로그래밍, 영상편집, UX/UI, 마케팅, 데이터 분석, 엑셀강의, The RED, 국비지원, 기업교육, 서비스 제공.
fastcampus.co.kr
본 포스팅은 패스트캠퍼스 환급 챌린지 참여를 위해 작성되었습니다.
'FastCampus 강의 > Python' 카테고리의 다른 글
패스트캠퍼스 챌린지 15일차 (Python) (0) | 2022.02.07 |
---|---|
패스트캠퍼스 챌린지 14일차 (Python) (0) | 2022.02.06 |
패스트캠퍼스 챌린지 12일차 (Python) (0) | 2022.02.04 |
패스트캠퍼스 챌린지 11일차 (Python) (0) | 2022.02.03 |
패스트캠퍼스 챌린지 10일차 (Python) (0) | 2022.02.02 |