@AshaRajagopal/

CheapAdvancedClosedsource

Python

No description

fork
loading
Files
  • main.py
main.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"""
Asha Rajagopal
Chapter 8 lab 3
TV lab
"""
class Television:
  """A virtual tv"""
  MAX_VOLUME = 10
  MAX_CHANNEL = 499
  
  def __init__(self, channel, volume, is_on = "no"):
    """ Initializes a Tv's attributes"""
    self._channel = channel
    self._volume = volume
    self._is_on = is_on

  def __str__(self):
    """string method"""
    if self._is_on == "yes":
      string = "TV:"
      string += "channel:" + self._channel
      string += "volume:" + self._volume
    else:
      print("The tv is not on")
  
  def toggle_power(self):
    """turns power on and off"""
    if self._is_on == "yes":
      self._is_on = "no"
      print("power turned off") #remove later
    else:
      self._is_on = "yes"
      print("power is turned on") #remove later
    return self._is_on

  def get_channel(self):
    """gets the channel"""
    return self._channel

  def set_channel(self, new_channel):
    """changes the channel"""
    if self._is_on == "yes":
      self._channel = new_channel
      return self._channel
    else:
      print("TV is turned off")
    

  def raise_volume(self):
    """raises the volume of the TV"""
    if self._is_on == "yes":
      if self._volume < 10:
        self._volume +=1
      else:
        print("The volume is already at it's max level")
      return self._volume
    else:
      print("TV is turned off")
    
  
  def lower_volume(self):
    """lowers the volume of the TV"""
    if self._is_on == "yes":
      if self._volume > 0:
        self._volume -=1
      else:
        print("The volume is already at it's lowest level")
      return self._volume
    else:
      print("TV is turned off")
    

def main():
  import random
  a_channel = random.randint(0,500)
  a_volume = random.randint(0,11)
  tv = Television(a_channel,a_volume, "yes")
  yon = input("Would you like to turn the tv on? ").lower
  if yon == "yes":
    tv.toggle_power()
  button = 2
  while button != 0:
    button = input("""
    enter the number you wish to access:
    0 - Exit
    1 - Toggle Power
    2 - Change Channel
    3 - Raise Volume
    4 - Lower Volume
    5 – Display Max Volume
    6 – Display Max Channel\n""")
    if button == "1":
      tv.toggle_power()
    elif button == "2":
      new_channel = random.randint(0,500)
      new = tv.set_channel(new_channel)
      print("The new channel is " + str(new))
    elif button == "3":
      change = tv.raise_volume()
      print("The volume is now: " + str(change))
    elif button == "4":
      change1 = tv.lower_volume()
      print("The volume is now: " + str(change1) )
    elif button == "5":
      print("the max volume is: " + str(Television.MAX_VOLUME))
    elif button == "6":
      print("the max channel is: " + str(Television.MAX_CHANNEL))
    else:
      print("TV off")
      break
  
main()