[python]클래스

young0_0·2022년 11월 8일
0

python

목록 보기
6/6

python 문법심화3

  • 클래스

클래스

class Monster():
	hp = 100
    alive = True
    
    def damage(self,attack):
    	self.hp = selp.hp - attack
        if self.hp < 0:
        	self.alive = False
            
    def status_check(self):
    	if self.alive:
        	print('살아있다.')
       	else:
        	print('죽었다')
            
    
    m = Monster()
    m.damage(120)
    
    m2.Monster()
    m2.damage(90)
    
    m.status_check() 	#죽었다.
    m2.status_check()	#살았다.
profile
열심히 즐기자ㅏㅏㅏㅏㅏㅏㅏ😎

0개의 댓글