[Tutor] Television
Noah Hall
enalicho at gmail.com
Sun Jun 26 16:51:27 CEST 2011
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
More information about the Tutor
mailing list