# 상속
# 클래스들에 중복된 코드를 제거하고 유지보수를 편하게 하기 위해서 사용

# 클래스 변수
# : 인스턴스들이 모두 공유하는 변수


# 부모 클래스
import random
class Monster:
    max_num = 1000
    def __init__(self, name, health, attack):
        self.name = name
        self.health = health
        self.attakc = attack
        Monster.max_num -= 1
    def move(self):
        print(f"[{self.name}] 지상에서 이동하기")


# 자식 클래스
class Wolf(Monster):
    pass

class Shark(Monster):
    def move(self):
        print(f"[{self.name}] 헤엄치기")

class Dragon(Monster):
    def __init__(self, name, health, attack):
        super().__init__(name, health, attack)
        self.skills = ("불뿜기", "꼬리치기", "날개치기")

    def move(self) :
        print(f"[{self.name}] 날기")
    
    def skill(self) :
        print(f"[{self.name}] 스킬사용 {self.skills[random.randint(0,2)]}")


wolf = Wolf("울프", 1500, 500)
wolf.move()
print(wolf.max_num)

shark = Shark("샤크", 3000, 400)
shark.move()
print(shark.max_num)

dragon = Dragon("드래곤", 8000, 800)
dragon.move()
dragon.skill()
print(dragon.max_num)

https://bit.ly/37BpXiC

 

패스트캠퍼스 [직장인 실무교육]

프로그래밍, 영상편집, UX/UI, 마케팅, 데이터 분석, 엑셀강의, The RED, 국비지원, 기업교육, 서비스 제공.

fastcampus.co.kr

 

본 포스팅은 패스트캠퍼스 환급 챌린지 참여를 위해 작성되었습니다.

BELATED ARTICLES

more