Hi guys, thanks for all the help lately, but I require some more :o
I need it that the user is able to choose what is on the controller, when I type in a valid option I test for it that it gets to that point but it does not complete the action.
Here is the code:
import random
class TV(object):
def __init__(self):
tvslct=("40 inch LCD","70 inch 3D","15 inch old school")
self.tv = random.choice(tvslct)
self.state = 0
self.channel = 1
self.channelnames=["BBC 1","BBC 2","ITV 1","Channel 4","FIVE","ITV2","BBC 3","ITV3","BBC 4","Sky 3","Yesterday","Channel 4+1","More 4","Film 4"]
print("You have been given a",self.tv,"Tv.")
print("The Tv has been setup.")
def turnon(self):
if self.state==1:
print("The Tv is already on.")
else:
self.state=1
print("The Tv has turned on.")
def turnoff(self):
if self.state==0:
print("The Tv is already off.")
else:
self.state=0
print("The Tv has turned off.")
def changechannels(self):
if self.state==1:
self.channel=999
while not self.channel in range(0,15):
try:
self.channel = int(input("Channel No."))
except ValueError:
print("Enter a integer between 0 and",self.channels,".")
print("The channel has been change to",self.channelnames[self.channel-1])
else:
print("The action could not be completed as the Tv is turned off.")
def findchannels(self):
if self.state==1:
self.channels=0
prevchannels=channels
self.channels=random.randint(0,15)
while self.channels < prevchannels:
randint(0,15)
print("The total Tv channels has been updated.")
print("The Tv now has",self.channels,"channels.")
else:
print("The action could not be completed as the Tv is turned off.")
def displaychannels(self):
print("You have",self.channels,"channels.")
print("Those channels are")
my_tv = TV()
QUIT=0
action=123
def wtd():
print("""
___________
/___________\\
| [Turn on] |
| [Turn off] |
| [Change |
| channels] |
| [Find |
| channels] |
| [Display |
| channels] |
| |
|_____________|
\___________/
____________
| Quit |
------------
""")
print("What would you like to do?")
while QUIT == 0:
wtd()
actions=("turnon","turnoff","changechannels","findchannels","displaychannels","quit")
while not action in actions:
try:
action=input("Action: ").lower()
except ValueError:
print("A action name, stated on the controller, is required.")
if action==("turnon"):
print("cheese")
my_tv.turnon
elif action==("turnoff"):
my_tv.turnoff
elif action==("changechannels"):
my_tv.changechannels
elif action==("findchannels"):
my_tv.findchannels
elif action==("displaychannels"):
my_tv.displaychannels
elif action==("quit"):
QUIT=1
action=123
I will be very grateful for any help!!!!