Just to add a little to Alexandre's answer. You can keep most of the code the
same just add in
farmlet[0].eat()
farmlet[1].eat()
and it will be okay... kinda. Or you could rewrite it and do it another
way... I'm guessing that you are using python 3 by your print statements, so I
don't think you need the int() around your input, even in python.2x input() was
safe for numbers I believe (the whole list will rip my throat out if I'm wrong
anyways, lol), but in your while loop around line 82 you have all the
conditions responding to a string, even thought you explicitly changed the
input to an integer.
if choice == "0"
instead of
if choice == 0:
so I got a continual output of
('\nSorry, but', 3, "isn't a valid choice.")
Now this does not get your program running the way you want it to, but it will
start you off making the corrections you need. Just some things to think about,
in line 113, when did you define class f?
in line 102, what are you trying to do, and are you telling it the right thing?
since you have 2 (or possibly more) critters you are taking care of, how does
the player know which one he is feeding / talking to / playing with in your
farmlet?
Anyways best of luck in your program, sounds pretty cool...
----
What is it about you... that intrigues me so?
________________________________
From: Alexandre Conrad <alexandre.con...@gmail.com>
To: David Merrick <merrick...@gmail.com>
Cc: tutor@python.org
Sent: Wednesday, June 22, 2011 6:48 PM
Subject: Re: [Tutor] Class methods
David,
2011/6/22 David Merrick <merrick...@gmail.com>:
> # listen to your critter
> elif choice == "1":
> for critter in farmlet:
> farmlet.talk()
You want to call .talk() on your "critter" instance which has the
.talk() method, not on farmlet (which is a list as the error message
states)
> Traceback (most recent call last):
> File "I:/Python/programs/critter_farm4.py", line 117, in <module>
> main()
> File "I:/Python/programs/critter_farm4.py", line 103, in main
> farmlet.talk()
> AttributeError: 'list' object has no attribute 'talk'
You will probably have a problem when calling talk() because it
references to the "farmlet" variable which doesn't exist in the scope
of your .talk() method.
HTH,
--
Alex | twitter.com/alexconrad
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor