<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Can someone show me how to code this correctly please<br>
<br>
&gt; class Critter(object):<br>
&gt;<br>
&gt;    def __init__(self, name, hunger = 0, boredom = 0):<br>
&gt;    def __pass_time(self):<br>
&gt;    def __str__(self):<br>
&gt;    @property<br>
&gt;    def mood(self):<br>
&gt;    def talk(self):<br>
&gt;    def eat(self):<br>
&gt;    def play(self):<br>
&gt;<br>
&gt; class Farm(Critter):<br>
<br>
I still don&#39;t think a Farm is a type of Critter...<br>
<br>
&gt;    def __init__(self,farmlet):<br>
&gt;       Critter.__init__(self,farmlet)<br>
<br>
This will set the name to farmlet, which I don&#39;t<br>
think you want.<br>
<br>
&gt;    def talk(self,farmlet):<br>
<br>
You don&#39;t need to pass farmlet in since the<br>
class has farmlet stored inside it.<br>
You can access farmlet with self.farmlet.<br>
<br>
&gt;        for critter in farmlet:<br>
&gt;            print(&quot;Hello&quot;)<br>
&gt;            Critter.talk(farmlet)<br>
<br>
You want the instance to talk not the class.<br>
So you need to use critter.talk() And the talk<br>
method does not take any arguments except<br>
self. What you are doing here is calling the<br>
class method with an instance value of farmlet.<br>
ie self in that method gets the value of farmlet.<br>
<br>
&gt; def main():<br>
&gt;    crit1 = Critter(&quot;Sweetie&quot;)<br>
&gt;    crit2 = Critter(&quot;Dave&quot;)<br>
&gt;    farmlet = [crit1,crit2]<br>
&gt;    f = Farm(farmlet)<br>
&gt;<br>
&gt;    choice = None<br>
&gt;    while choice != &quot;0&quot;:<br>
&gt;        print \<br>
&gt;        (&quot;&quot;&quot;<br>
&gt;        Critter Caretaker<br>
&gt;<br>
&gt;        0 - Quit<br>
&gt;        1 - Listen to your critter<br>
&gt;        2 - Feed your critter<br>
&gt;        3 - Play with your critter<br>
&gt;        &quot;&quot;&quot;)<br>
&gt;<br>
&gt;        choice = input(&quot;Choice: &quot;)<br>
&gt;        print()<br>
&gt;<br>
&gt;        # exit<br>
&gt;        if choice == &quot;0&quot;:<br>
&gt;            print(&quot;Good-bye.&quot;)<br>
&gt;<br>
&gt;        # listen to your critter<br>
&gt;        elif choice == &quot;1&quot;:<br>
&gt;            f.talk(farmlet)<br>
&gt;<br>
&gt;        # feed your critter<br>
&gt;        elif choice == &quot;2&quot;:<br>
&gt;            f.eat(farmlet)<br>
<br>
Note that f.eat is a method you inherit from Critter.<br>
The Critter method does not take any arguments<br>
so this will fail.<br>
<br>
&gt;        # play with your critter<br>
&gt;        elif choice == &quot;3&quot;:<br>
&gt;            f.play(farmlet)<br>
<br>
Same with f.play()<br>
<br>
&gt; Traceback (most recent call last):<br>
&gt;  File &quot;D:/David/Python/programs/critter_farm3.py&quot;, line 72, in talk<br>
&gt;    Critter.talk(farmlet)<br>
&gt;  File &quot;D:/David/Python/programs/critter_farm3.py&quot;, line 38, in talk<br>
&gt;    print(&quot;I&#39;m&quot;, <a href="http://self.name" target="_blank">self.name</a>, &quot;and I feel&quot;, self.mood, &quot;now.\n&quot;)<br>
&gt; AttributeError: &#39;list&#39; object has no attribute &#39;name&#39;<br>
<br>
This is because you are accessing the method via<br>
the class and passing farmlet as the instance value<br>
rather than sending the message to the innstance<br>
directly. Use<br>
<br>
critter.talk()   # and no farmlet needed!<br>
<br>
HTH,<br>
<br>
<br>
--<br>
Alan Gauld<br>
Author of the Learn to Program web site<br>
<a href="http://www.alan-g.me.uk/" target="_blank">http://www.alan-g.me.uk/</a><br>
<br>
<br>
<br>
<br>
</blockquote></div><br>