-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclasses.py
68 lines (60 loc) · 1.92 KB
/
classes.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
class Television:
"""
Class for Television objects.
"""
MIN_CHANNEL = 0 # Minimum TV channel
MAX_CHANNEL = 3 # Maximum TV channel
MIN_VOLUME = 0 # Minimum TV volume
MAX_VOLUME = 2 # Maximum TV volume
def __init__(self) -> None:
"""
Initialize a Television object.
"""
self.__channel: int = Television.MIN_CHANNEL
self.__volume: int = Television.MIN_VOLUME
self.__status: bool = False
def power(self) -> None:
"""
Function turns TV on and off.
"""
if self.__status:
self.__status = False
else:
self.__status = True
def channel_up(self) -> None:
"""
Function raise the current channel.
"""
if self.__status:
if self.__channel < Television.MAX_CHANNEL:
self.__channel += 1
else:
self.__channel = Television.MIN_CHANNEL
def channel_down(self) -> None:
"""
Function lowers the current channel.
"""
if self.__status:
if self.__channel > Television.MIN_CHANNEL:
self.__channel -= 1
else:
self.__channel = Television.MAX_CHANNEL
def volume_up(self) -> None:
"""
Function raises the current volume.
"""
if self.__status:
if self.__volume < Television.MAX_VOLUME:
self.__volume += 1
def volume_down(self) -> None:
"""
Function lowers the current volume.
"""
if self.__status:
if self.__volume > Television.MIN_VOLUME:
self.__volume -= 1
def __str__(self) -> str:
"""
Overrides normal __str__ functionality to return the status of the Television object.
"""
return f'TV status: Is on = {self.__status}, Channel = {self.__channel}, Volume = {self.__volume}'