最新回答 / 陌上花開歸期
def __str__(self):? ? ? ? c, d = self.fun()? ? ? ? return '%d/%d' % (c, d)? ? __repr__ = __str__? ??? ? def fun(self):? ? ? ? a, b = self.p, self.q? ? ? ? if a > b:? ? ? ? ? ? a, b = b, a? ? ? ? r = 1? ? ? ? while r != 0:? ? ? ? ? ? r = a % b? ? ? ? ? ...
2020-05-13
def calc_prod(lst):
def cprod():
x = 1
for n in lst:
x = n * x
return x
return cprod
f = calc_prod([1, 2, 3, 4])
print f()
def cprod():
x = 1
for n in lst:
x = n * x
return x
return cprod
f = calc_prod([1, 2, 3, 4])
print f()
2020-05-12
最新回答 / 飄香的城堡_hoILT5
描述reduce()?函數會對參數序列中元素進行累積。函數將一個數據集合(鏈表,元組等)中的所有數據進行下列操作:用傳給 reduce 中的函數 function(有兩個參數)先對集合中的第 1、2 個元素進行...
2020-05-07
def calc_prod(lst):
def cheng(x,y):
return x*y
def fiterinfo():
return reduce(cheng,lst)
return fiterinfo
f = calc_prod([1, 2, 3, 4])
print f()
def cheng(x,y):
return x*y
def fiterinfo():
return reduce(cheng,lst)
return fiterinfo
f = calc_prod([1, 2, 3, 4])
print f()
2020-05-02
def cmp_ignore_case(s1, s2):
if(s1[0].lower()>s2[0].lower()):
return 1
else:
return -1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if(s1[0].lower()>s2[0].lower()):
return 1
else:
return -1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2020-05-02
最新回答 / 慕運維5384406
因為是閉包呀,課程里也說了閉包不會直接輸出結果,而是輸出一個能得到結果的函數,需要結果的時候再調用函數即可。不管你后面f是多少,你要想調用可以輸入你想要的即可,而不是全都要。即使全都要也可以寫一個for循環把它遍歷出來
2020-04-28
最新回答 / _mango
<...code...>import mathdef is_sqr(x):??? return math.sqrt(x) %1==0print filter(is_sqr, range(1, 101))
2020-04-28