Quick Little Challenge

Page 1 of 1

0 Replies - 663 Views - Last Post: 12 January 2009 - 11:17 AM

#1 gl3thr0

• D.I.C Regular

Reputation: 19
• Posts: 319
• Joined: 27-October 07

Quick Little Challenge

Posted 12 January 2009 - 11:17 AM

no this is not a homework assignment
code was written by Alex Matelli and Anna Ravenscroft

guess the ouput. without running it of course

```import math

class EmilyWasWrong (Exception): pass

def do_compare(item):
action ={sea:(hold,'blue'),sky:(put,'side'),God:(heft,'pound')}
verb, attribute = action[item]
return verb(getattr(brain, attribute), getattr(item,attribute))

def put (brain_side, sky_side):
if sky_side in brain_side and ease in brain_side and you in brain_side:
return 'wider'
else: raise EmilyWasWrong('put')

def hold (brain_color,sea_color):
if absorb(brain_color,sea_color) == absorb (buckets,sponges):
return 'deeper'
else: raise EmilyWasWrong('hold')

def heft (brain_weight, God_weight):
if abs (brain_weight-God_weight) <= abs(syllable-sound):
return 'just the weight'
else: raise EmilyWasWrong('heft')

class Thing (object):
def __init__(self,**a): self.__dict__=a

sea = Thing(blue='deep')
sky = Thing(side='up')
God = Thing(pound=(1.0+math.sqrt(5.0))/2.0)
ease = 'easy'
you = 'xx'

def absorb (container,item):
return item in container

sponges = 'absorb liquids'
buckets = [sponges]
syllable = 256.1
sound = 256.0
class Brain (object):
side = 'up easy xx'.split()
blue = ['deep']
pound = 1.61
brain = Brain()
for comparison in (sky,sea,God):
print do_compare(comparison)
print

```

Is This A Good Question/Topic? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }