[Tutor] Ummmmmm, suggestions please?
Christian Tismer
tismer@appliedbiometrics.com
Wed, 16 Jun 1999 19:26:10 +0200
"Kenneth M. Power" wrote:
> room1.show()
> Item Volume
> Box(2) 10 #Or something similar
> Total Volume: 10
>
> Any suggestions on how to accomplish this?
You might want to add a summary function, like so:
def summary(self):
collector = {}
countall, spaceall = (0,0)
for thing in self.contents:
name = thing.code
cube = thing.cube
count, sofar = collector.get(name, (0,0) )
collector[name] = count+1, sofar + cube
countall, spaceall = countall+1, spaceall+cube
result = collector.items()
result.sort()
print "Item\t\tVolume"
for name, (manifold, space) in result:
print "%s(%d)\t\t%d" % (name, manifold, space)
print "%d Objects, total volume=%d" % (countall, spaceall)
And please, next time submit tested code.
Yours had about three bugs.
ciao - chris
--
Christian Tismer :^) <mailto:tismer@appliedbiometrics.com>
Applied Biometrics GmbH : Have a break! Take a ride on Python's
Kaiserin-Augusta-Allee 101 : *Starship* http://starship.python.net
10553 Berlin : PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF
we're tired of banana software - shipped green, ripens at home