Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # TV Controller
- # Select a channel and change the volume
- class TV(object):
- def __init__(self, channel = 0, volume = 5):
- self.channel = channel
- self.volume = volume
- def change_channel(self):
- self.channel = int(input("Choose a channel between 1 to 3: "))
- if 0 < self.channel <= 3:
- print("\nOk, channel", self.channel)
- else:
- print("\nSorry, but", self.channel, "isn't a valid choice.")
- def decrease_volume(self, change = 1):
- self.volume -= change
- if self.volume < 0:
- self.volume = 0
- print("Now volume is", self.volume)
- def increase_volume(self, change = 1):
- self.volume += change
- if self.volume > 10:
- self.volume = 10
- print("Now volume is", self.volume)
- def main():
- tv = TV()
- choice = None
- while choice != "0":
- print \
- ("""
- TV Controller
- 0 - Quit
- 1 - Change a Channel
- 2 - Decrease a Volume
- 3 - Increase a Volume
- """)
- choice = input("Choise: ")
- print()
- # exit
- if choice == "0":
- print("Good-bye.")
- # change a channel
- elif choice == "1":
- tv.change_channel()
- # decrease a volume
- elif choice == "2":
- tv.decrease_volume()
- # increase a volume
- elif choice == "3":
- tv.increase_volume()
- # some unknown choice
- else:
- print("\nSorry, but", choice, "isn't a valid choice.")
- main()
- input("\n\nPress the enter key to exit.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement