I have stated to make a program called virtual Tv, I have been having troubles with variabels and I need the variable: state to be able to be change and accessed outside the class and inside, but I think that state is a local variable at the moment.
import random
state=0
class TV(state):
tv=None
def __init__(tv):
tvslct=("40 inch LCD","70 inch 3D","15 inch old school")
tv=random.choice(tvslct)
print("You have been given a",tv,"Tv.")
print("The Tv has been setup")
def turnon(state):
if state==1:
print("The Tv is already on.")
else:
state=1
print("The Tv has turned on.")
def turnoff(state):
if state==0:
print("The Tv is already off.")
else:
state=0
print("The Tv has turned off.")
def changechannel(state):
if state==1:
print("It has changed.")
else:
print("The action could not be completed as the Tv is turned off.")
def findchannel(state):
if state==1:
prevchannels=channels
channels=randint(0,15)
while channels < prevchannels:
randint(0,15)
print("The total Tv channels has been updated.")
print("The Tv now has",channels,"channels.")
else:
print("The action could not be completed as the Tv is turned off.")
TV()
TV.turnon(state)
print(state)
TV.turnoff(state)
print(state)
TV.turnon(state)
print(state)
Could you please edit the code to change it and I will be able to learn from the differences, thanks :)