def count():
fs = []
for i in range(1, 4):
def f6_1(i):
def f6_2():
return i*i
return f6_2
fs.append(f6_1(i))
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
fs = []
for i in range(1, 4):
def f6_1(i):
def f6_2():
return i*i
return f6_2
fs.append(f6_1(i))
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
2015-03-27
def __init__(self):
pass
def __call__(self, num):
def g(x):
if x == 0:
return 0
if x == 1:
return 1
else:
return g(x-2) + g(x-1)
return [g(x) for x in range(num)]
pass
def __call__(self, num):
def g(x):
if x == 0:
return 0
if x == 1:
return 1
else:
return g(x-2) + g(x-1)
return [g(x) for x in range(num)]
2015-03-27
def __sub__(self, r):
return Rational(self.p * r.q - self.q * r.p, self.q * r.q)
def __mul__(self, r):
return Rational(self.p * r.p , self.q * r.q)
def __div__(self, r):
return Rational(self.p * r.q , self.q * r.p)
return Rational(self.p * r.q - self.q * r.p, self.q * r.q)
def __mul__(self, r):
return Rational(self.p * r.p , self.q * r.q)
def __div__(self, r):
return Rational(self.p * r.q , self.q * r.p)
2015-03-26
def GCD(a,b):
if b==0:
return a
else:
return GCD(b,a%b)
r=GCD(p,q)
self.p = p/r
self.q = q/r
if b==0:
return a
else:
return GCD(b,a%b)
r=GCD(p,q)
self.p = p/r
self.q = q/r
2015-03-26
def calc_prod(lst):
def prod1(x, y):
return x*y
def prod():
#calc the prod
return reduce(prod1, lst)
return prod
f = calc_prod([1, 2, 3, 4])
print f()
def prod1(x, y):
return x*y
def prod():
#calc the prod
return reduce(prod1, lst)
return prod
f = calc_prod([1, 2, 3, 4])
print f()
2015-03-26
import math
def is_sqrt(x):
return math.sqrt(x).is_integer()
def is_sqrt(x):
return math.sqrt(x).is_integer()
2015-03-25