-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtv.py
32 lines (26 loc) · 824 Bytes
/
tv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class TV:
"""A television.
number_channels: the number of channels this TV has.
"""
def __init__(self, number_channels):
self._on = False
self._channel = 0
self._channels = number_channels
def power(self):
"""Toggle between `on' and `off' states."""
self._on = not self._on
def is_on(self):
"""Return True when `on', False otherwise."""
return self._on
def channel_up(self):
if self._on:
self._channel += 1
self._channel %= self._channels
def channel_down(self):
if self._on:
self._channel -= 1
self._channel %= self._channels
def channel(self):
"""Return the current channel number, if `on'."""
if self._on:
return self._channel