[Tutor] On off Toggle

David Hutto smokefloat at gmail.com
Sat Mar 12 11:22:44 CET 2011


You want toggle_power to turn on or off.

class Television(object):
    def __init__(self):
        pass

    def toggle_power(self, choice):

        if choice == 0:
            poweroff()
        if choice == 1:
            poweron()

# you set  a choice that won't work unless user says
choice = 1000
#you giv an off on status
Off = 0
On = 1
You start the loop instance
while choice != 0:
    #Ask for input 0 or 1
    choice = raw_input("Power on = 1, power off = 0 . Press 1, or 0 : ")
    #give an instance for the class
    tv = Television()
    #give class and function instance to call toggle_power
    tv.toggle_power(choice)
once the function is called, the choice is passed to the function and
the poweron(), or poweroff() function is called.


More information about the Tutor mailing list