|
Please explain what I've done wro: msg#00161python.pygame
it seems to me that you should not write Person.population etc, but self.population When all person. is replaced by self. the code works as promised! : class Person: population=0 def __init__(self,name): self.name=name print '(Initialising %s)' % self.name self.population += 1 def __del__(self): print "%s says bye." % self.name self.population -= 1 if self.population == 0: print "I am the last one" else: print "There are still %d people left." % self.population def sayHi(self): '''Greeting by the person. That's all it does.''' print "Hi, my name is %s" % self.name def howMany(self): if self.population==1: print "I am on the only person here." else: print "We have %d persons here." % self.population Jason=Person("Jason") Jason.sayHi() Jason.howMany() Sophie=Person("Sophie") Sophie.sayHi() Sophie.howMany() Jason.sayHi() |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: fade out surfaces: 00161, Luke Miller |
|---|---|
| Next by Date: | Re: optimising render code: 00161, andrew baker |
| Previous by Thread: | Please explain what I've done wrong.i: 00161, Jason |
| Next by Thread: | pygext: Couldn't find matching GLX visual: 00161, Christopher Arndt |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |