[Tutor] Television

Vincent Balmori vincentbalmori at yahoo.com
Sun Jun 26 03:02:31 CEST 2011


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.
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 


Alan Gauld wrote:
> 
> 
> "Vincent Balmori" <vincentbalmori at yahoo.com> wrote
> 
>> Before I can even start correcting my code this error shows up.
> 
> You will find it much easier to write programns if you do
> not write out the whole program and then try to debug it!
> Just write a single method at a time and get that working
> before trying to debug a whole complex aopplication.
> 
> This code is fuill of errors whicvh will continually prevent
> you from running the code. I'll highlight a few. But as I
> said in your previous thread, you really need to read
> some more about the basics because your errors reveal
> a deep gap in your understanding of  variables, data types
> and their operations. Only once you undertsand that thoroughly
> will you be successful with classes and objects, because
> in OOP you are defining new data types and operations.
> If you can't use the standard types you have little hope
> of using newly defined ones!
> 
> Some examples:
> 
> class Television(object):
>     def __init__(tv, channel = range(0,10), volume = range(0,10)):
>         tv.channel = channel
>         tv.volume = volume
>     def cha(tv, level = 1):
>         while 0 >= tv.channel <=10:
> 
> Here you store two range objects as your channel and
> volume attributes in init (In Python v 2 these would be
> lists but in Python 3 they are range objects).
> Then in cha() you try to compare them to a number,
> that won't work, they are incompatible types.
> Later you try to increment channel which agaion won't
> work. (And why you only increment channel and never
> decrement is a puzzle - and you ignore the level value
> read from the user?)
> 
> Similar applies in volu() except you have two methods,
> one up one down. But you are still trying to apply
> integer operations to range objects.
> 
> 
> In various places you do this:
> 
>       if level > 10:
>             int(input("\n That's too much! Choose another number?: "))
> 
> The user input is read, converted to an int then thrown away.
> You need to store it in a variable.
> 
> Finally we come to the error message, it is in main():
> 
> def main():
>     print(Television(tv.display))
>     choice = None  Notice you do not create a tv instance. You try to 
> print an instance but in creating it you try to passs tv.display to 
> the constructor, but tv does not exist aty that point. And even if you 
> did succeed the instance would be immediately destroyed again because 
> you are not storing it in a variable. You need to go back to basic 
> data types and understand that concept. There is clearly something 
> missing at the moment since you jkeep making the same mistakes over 
> and over again.> thought I had already created the "tv" instance.> 
> http://old.nabble.com/file/p31925053/Television Television You defined 
> a class. You tried to create an instance of the class inside the print 
> statement, but it nevergot that far.Try reading my tutorial topic on 
> data - The Raw Materials - and then the OOP topic. Then go back to 
> whatever tutorial you are currently following and see if it helps.--  
> Alan GauldAuthor of the Learn to Program web 
> sitehttp://www.alan-g.me.uk/ 
> 
> 
> _______________________________________________
> 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-tp31925053p31928968.html
Sent from the Python - tutor mailing list archive at Nabble.com.



More information about the Tutor mailing list