리모컨 클래스
채널과 음량을 변화량으로 조절하는 RemoteControl 클래스를 작성하시오.
작성할 클래스
다음 형태의 클래스를 작성한다.
class RemoteControl:
def __init__(self, channel, volume, maxChannel):
# 코드를 작성하세요.
def changeChannel(self, amount):
# 코드를 작성하세요.
def changeVolume(self, amount):
# 코드를 작성하세요.
def getChannel(self):
# 코드를 작성하세요.
def getVolume(self):
# 코드를 작성하세요.
- 생성자
__init__(channel, volume, maxChannel)은 초기 채널, 초기 음량, 채널의 최댓값을 저장한다. changeChannel(amount)는 현재 채널에amount를 더한다. 결과가 1보다 작으면 1,maxChannel보다 크면maxChannel로 조정하고 값을 반환하지 않는다.changeVolume(amount)는 현재 음량에amount를 더한다. 결과가 0보다 작으면 0, 100보다 크면 100으로 조정하고 값을 반환하지 않는다.getChannel()은 현재 채널을int로 반환한다.getVolume()은 현재 음량을int로 반환한다.
클래스를 사용하는 코드
작성한 클래스는 아래 코드와 함께 실행된다.
channel, volume, maxChannel = map(int, input().split())
q = int(input())
remote = RemoteControl(channel, volume, maxChannel)
for _ in range(q):
command = input().split()
if command[0] == "channel":
result = remote.changeChannel(int(command[1]))
print(type(result))
elif command[0] == "volume":
result = remote.changeVolume(int(command[1]))
print(type(result))
elif command[0] == "getChannel":
result = remote.getChannel()
print(result)
print(type(result))
else:
result = remote.getVolume()
print(result)
print(type(result))
위 코드가 정상적으로 동작하도록 클래스를 작성한다. 제출할 때는 작성한 클래스의 정의 전체만 제출한다. 입력을 받거나 객체를 생성하는 코드는 제출하지 않는다.
입력
첫째 줄에 초기 채널 channel, 초기 음량 volume, 최대 채널 maxChannel이 주어진다.
둘째 줄에 명령의 개수 \(Q\)가 주어진다.
다음 \(Q\)개의 줄에 다음 명령 중 하나가 주어진다.
channel amount:changeChannel(amount)를 호출한다.volume amount:changeVolume(amount)를 호출한다.getChannel:getChannel()을 호출한다.getVolume:getVolume()을 호출한다.\(1 \le channel \le maxChannel \le 1,000,000,000\)
- \(0 \le volume \le 100\)
- \(1 \le Q \le 1,000\)
- \(-1,000,000,000 \le amount \le 1,000,000,000\)
출력
각 channel과 volume 명령에서는 호출한 메서드가 반환한 값의 자료형을 출력한다.
각 getChannel과 getVolume 명령에서는 현재 값과 반환값의 자료형을 출력한다.
각 메서드를 호출한 뒤에는 반환값의 자료형도 출력한다.
예제 입력 1
10 30 100
10
getChannel
getVolume
channel 95
getChannel
volume 80
getVolume
channel -150
volume -130
getChannel
getVolume
예제 출력 1
10
<class 'int'>
30
<class 'int'>
<class 'NoneType'>
100
<class 'int'>
<class 'NoneType'>
100
<class 'int'>
<class 'NoneType'>
<class 'NoneType'>
1
<class 'int'>
0
<class 'int'>
예제 설명 1
처음 채널은 \(10\), 음량은 \(30\), 최대 채널은 \(100\)이다.
- 처음
getChannel과getVolume은 각각10과30을 반환한다. channel 95를 적용하면 계산값은 \(105\)이지만 최대 채널이 \(100\)이므로 채널은100이 된다.volume 80을 적용하면 계산값은 \(110\)이지만 음량의 최댓값이 \(100\)이므로 음량은100이 된다.channel -150을 적용하면 채널은 최솟값1이 된다.volume -130을 적용하면 음량은 최솟값0이 된다.
예제 입력 2
1 0 1
8
channel 100
volume 100
getChannel
getVolume
channel -100
volume -100
getChannel
getVolume
예제 출력 2
<class 'NoneType'>
<class 'NoneType'>
1
<class 'int'>
100
<class 'int'>
<class 'NoneType'>
<class 'NoneType'>
1
<class 'int'>
0
<class 'int'>
코멘트