440,715 Members | 748 Online Need help? Post your question and get tips & solutions from a community of 440,715 IT Pros & Developers. It's quick & easy.

# to calculate the universal distribution of continued fraction expansion

 P: 2 Hi all, I'm studying python program in uni. my lecture asks us to calculate the universal distribution of continued fraction expansion But I always have an error says: TypeError: 'builtin_function_or_method' object is not subscriptable. here's my algorithm: Expand|Select|Wrap|Line Numbers def universal_distro(N=10000):         import random     x = random.random()     g = list()     m = dict()     o = dict()     N = len(o)     while N < 10000:         for x in range[0,1]:             w = number2cfe(x,N=15)             e = w[n]             if n < 15:                 count = 0                 if w[n] not in g:                     for e in w:                         if e == w[n]:                             count += 1                     g.append(w[n])                 n += 1                 m[w[n]] = count         for k in m.keys():             if o.has_key(k):                 o[k] += m[k]             else:                 o[k] = m[k]         N += 1     return o   >>> universal_distro(10000) File "", line 9, in universal_distro     for x in range[0,1]: TypeError: 'builtin_function_or_method' object is not subscriptable   Can someone help me out? thanks Sep 3 '11 #1
3 Replies

 P: 1 ohh I think your syntax is incorrect for the Range() try using ( instead of [ Sep 3 '11 #2

 P: 2 Hi I want to calculate the distribution of continued fraction expansion (of N up to 10000). I think I need to choose a random variable x and calculate its cfe for n = 15, then store the counts in a dictionary. Then, choose another random variable x and continue the calculation until the size of the dictionary reaches 10000. But I just can't let my program understand this idea. Sep 4 '11 #3

 Expert 100+ P: 621 You don't use the random numbers anywhere? Explain in more detail what you want to do (the single letter variable names give me no clue). Also, you now have "x" defined twice Expand|Select|Wrap|Line Numbers     x = random.random() # # and --> note that this is a bogus statement as it will only execute once         for x in range[0,1]:  # should be range(0, 1) # # perhaps you want something more like import random for x in xrange(0, 10): ## but you would use while len(a_dict) < 10000:     print random.random()  Sep 4 '11 #4 