software facilities for teaching mathematics, part 2

I thought I’d follow up on my post about using a “Deal or No Deal”-type game to teach math.  If I were starting off with beginners to Python, I probably wouldn’t use so much functional syntax, but I thought I better show some code.

# "Deal or no deal"-isomorphic game
import math

values = [0.01, 1, 5, 10, 25, 50, 75, 100, 200, 300, 400, 500, 750, 1000, 5000, 10000, 25000, 50000, 75000, 100000, 200000, 300000, 400000, 500000, 750000, 1000000]

class Possibilities(object):
    def __init__(self, possibilities=values):
    def E(self, fcn):
        return sum(list(map(fcn, self.possibilities)))/len(self.possibilities)
    def mean(self):
        return self.E(lambda x: x)
    def standard_deviation(self):
        return math.sqrt(self.E(lambda x: x*x)-self.mean()**2)
    def population_deviation(self):
        return self.standard_deviation()*math.sqrt(n/(n-1))
    def beat(self, val):
        m=len(list(filter(lambda x: x>=val, self.possibilities)))
        return m/n
    def remove(self, n):
    def __contains__(self, n):
        return n in self.possibilities
    def __str__(self):
        return 'The '+str(len(self.possibilities))+' possibilities are: '+str(self.possibilities)+'\n mean='+str(self.mean())+' ; SD='+str(self.standard_deviation())+'\n P(beating mean)='+str(self.beat(self.mean()))

if __name__=='__main__':
        inp = input('What value was revealed? ')
        float_val = float(inp)
        if float_val in x:
            print(float_val, 'is not a possible value.')
    print('You win', x.possibilities[0])    
Published in: on 2009.06.25 at 21:17  Leave a Comment  
Tags: , , , , ,

The URI to TrackBack this entry is:

RSS feed for comments on this post.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: