본문 바로가기
프로그램

[파이썬] 문제 : TV 클래스 만들기

by 오디세이99 2023. 12. 14.
728x90
반응형

class TV():
    def __init__(self, on, ch, vol):
        self.on = on
        self.channel = ch
        self.volume = vol
        
    def turnOn(self):
        self.on = True
        
    def turnOff(self):
        self.on = False
        
    def setChannel(self, channel):
        self.channel = channel
        print('TV의 채널:',self.channel)
    
    def setVolume(self, volume):
        self.volume = volume
        print('TV의 음량:',self.volume)
        
tv = TV(True, 0, 0)          # 전원 On(True)하고, 채널=0, 볼륨=0 으로 객체(인스타스) 생성
tv.setChannel(11)
tv.setVolume(6)

728x90
반응형

댓글