[Tutor] Television

Vincent Balmori vincentbalmori at yahoo.com
Sun Jun 26 21:28:54 CEST 2011


I made in elif statement for the channel changer that works for it, but the
volume systems system boundary does not the way I want it to. If the volume
is 2 and I lower it by a value of 5, it will accept the volume at a negative
number thus going past the boundary. The vice-versa for the high boundary as
well.

http://old.nabble.com/file/p31932639/TV.py TV.py 


Noah Hall-3 wrote:
> 
> On Sun, Jun 26, 2011 at 2:02 AM, Vincent Balmori
> <vincentbalmori at yahoo.com> wrote:
>>
>> It's working better now. The problem I have left is that I have to set
>> the
>> channel and volume values in a range (for both I intend for 0-10). I
>> thought
>> the range() would be the choice, but probably I'm not using it right.
> 
> I think the best way to do this is probably to set two properties -
> tv.channel_boundary and tv.volume_boundary, this is presuming that you
> don't want to allow the lower boundary to be changed. If you do,
> create an upper and lower boundary variable for each.
> 
>>def channel_remote(tv, level = 1):
>>        if tv.channel in range(0,10):
> 
> Here, it'd be better if you used
> if tv.channel < 10:
> 
> That way you're not wasting a whole list and a list search just to
> test if something is less than ten.
> Using the boundaries, that would be
> if tv.channel < tv.channel_boundary:
> 
> There's also no need for this, not here, anyway. You should be testing
> in __init__, where the channel can be set incorrectly.
> 
>>            level = int(input("\n Which channel do you want to go up to:
>> "))
> 
> Why have this when you allow level as an argument? It's a waste.
> 
>>            if 0 > level > 10:
>>                int(input("\n That's not valid! Choose another channel:
>> "))
>>            else:
>>                tv.channel += level
> 
> This is your second problem you've found, I guess?
> Well, how about this
> tv.channel = level
> Easy, right? :)
> 
>>                print("\n The channel is now:", tv.channel)
> 
> 
>> Another one is for the tv.channel to hold a new value instead of just
>> adding/subtracting the value and the only way I can think how is to use a
>> list and then have the function replace the value each time. I'm sure
>> there
>> is a better way though.
>> http://old.nabble.com/file/p31928968/TV TV
> 
> 
> HTH
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 
> 

-- 
View this message in context: http://old.nabble.com/Television-tp31925053p31932639.html
Sent from the Python - tutor mailing list archive at Nabble.com.



More information about the Tutor mailing list