[Tutor] two questions..
Kirby Urner
urnerk@qwest.net
Wed, 14 Nov 2001 16:47:57 -0800
>
>Could this be done by having the regular calculations for body weight look
>for any modifier thingamabobs and if it found some, factor that into the
>calculations, and if not, then just do the calculations as normal?
Sure, why not?
>>> class Body:
def __init__(self):
self.modifiers = {} # define thingamabobs here
>>> b = Body()
>>> b.modifiers
{}
>>> b.modifiers['fat content'] = 20
>>> class Process:
def checkfat(self, body):
bmods = body.modifiers
if 'fat content' in bmods: # fat checker
if bmods>15:
print "Sorry, too fat"
else:
print 'OK, normal' # default even if no value
>>> p = Process()
>>> p.checkfat(b)
Sorry, too fat
>>> b2 = Body()
>>> p.checkfat(b2) # b2 has no fat content thingamabob
OK, normal
Kirby