def calc_prod(lst):
def cheng(x,y):
return x*y
def chenglist():
return reduce(cheng,lst)
return chenglist
f = calc_prod([1, 2, 3, 4])
print f()
def cheng(x,y):
return x*y
def chenglist():
return reduce(cheng,lst)
return chenglist
f = calc_prod([1, 2, 3, 4])
print f()
2018-03-08
def calc_prod(lst):
def lazy_calc_prod():
def prod(x,y):
return x*y
return reduce(prod,lst)
return lazy_calc_prod
f = calc_prod([1, 2, 3, 4])
print f()
def lazy_calc_prod():
def prod(x,y):
return x*y
return reduce(prod,lst)
return lazy_calc_prod
f = calc_prod([1, 2, 3, 4])
print f()
2018-03-08
要把题目中<Student: name, gender, score>的“Student”改为“student”,把“<”和">"改为“(”和")",把index.py里写好的s = Student('Bob', 'male', 88)中的"Bob"改为“bob”
老师这bug....
老师这bug....
2018-03-08
import math
def is_sqr(x):
return math.sqrt(x)==int(math.sqrt(x))
print filter(is_sqr,range(1,101))
def is_sqr(x):
return math.sqrt(x)==int(math.sqrt(x))
print filter(is_sqr,range(1,101))
2018-03-08
try:
print Person.__count
except AttributeError:
print 'AttributeError'
print Person.__count
except AttributeError:
print 'AttributeError'
2018-03-08
def format_name(s):
return s[0].upper()+s[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
return s[0].upper()+s[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
2018-03-08
import math
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, math.sqrt)
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, math.sqrt)
2018-03-08
递归函数法:
class Fib(object):
省略初始化部分
self.L=[]
for x in range(num):
def fn(x):
if x==0:
return 0
elif x==1:
return 1
return fn(x-2)+fn(x-1)
self.L.append(fn(x))
def __str__(self):
return '%s'%self.L
def __len__(self):
return len(self.L)
class Fib(object):
省略初始化部分
self.L=[]
for x in range(num):
def fn(x):
if x==0:
return 0
elif x==1:
return 1
return fn(x-2)+fn(x-1)
self.L.append(fn(x))
def __str__(self):
return '%s'%self.L
def __len__(self):
return len(self.L)
2018-03-08
def realprod(a,b):
return a * b
def calc_prod(lst):
def prod():
return reduce(realprod,lst)
return prod
f = calc_prod([1, 2, 3, 4])
print f()
return a * b
def calc_prod(lst):
def prod():
return reduce(realprod,lst)
return prod
f = calc_prod([1, 2, 3, 4])
print f()
2018-03-07