인프런 커뮤니티 질문&답변
오류관련
작성
·
240
0
class Unit:
def __init__(self,name,hp,damage):
self.name=name
self.hp=hp
self.damage=damage
print('{0} 유닛이 생성 되었습니다.'.format(self.name))
print('체력 {0}, 공격력 {1}'.format(self.hp,self.damage))
class AttackUnit:
def __init__(self,name,hp,damage):
self.name=name
self.hp=hp
self.damage=damage
def attack(self,location):
print('{0} : {1} 방향으로 적군을 공격 합니다. [공격력 {2}'\
.format(self.name,location,self.damage))
def damaged(self,damage):
print('{0} : {1} 데미지를 입었습니다.'.format(self.name,damage))
self.hp-=damage
print('{0} : 현재 체력은 {1} 입니다.'.format(self.name,self.hp))
if self.hp<=0:
print('{0} : 파괴되었습니다.'.format(self.name))
firebat1 = AttackUnit("파이어뱃",50,16)!!!!!
firebat1.attack('5시')
firebat1.damaged(25)
firebat1.damaged(25)
느낌표 있는 줄에서 AttackUnit이 정의되지 않았다고 뜹니다...
퀴즈
여러 개의 유사한 대상을 표현할 때, 각각 별도의 변수를 사용하는 것보다 클래스를 활용하는 것이 왜 더 효율적일까요?
변수 이름 규칙이 더 단순해져서
코드의 중복을 줄이고 관리하기 쉬워져서
프로그램 실행 속도가 훨씬 빨라져서
메모리 사용량이 크게 줄어들어서
답변
답변을 기다리고 있는 질문이에요
첫번째 답변을 남겨보세요!





