def prod(lst):
def _prod():
def multi(x,y):
return x*y
return reduce(multi,lst)
return _pord
x=pord([1,2,3,4])
x()
def _prod():
def multi(x,y):
return x*y
return reduce(multi,lst)
return _pord
x=pord([1,2,3,4])
x()
2018-10-18
可以通过的代码如下,需要处理异常:
class Person(object):
__count = 0
def __init__(self, name):
Person.__count += 1
self.name = name
print Person.__count
p1 = Person('Bob')
p2 = Person('Alice')
try:
print Person.__count
except AttributeError:
print 'attributeerror'
class Person(object):
__count = 0
def __init__(self, name):
Person.__count += 1
self.name = name
print Person.__count
p1 = Person('Bob')
p2 = Person('Alice')
try:
print Person.__count
except AttributeError:
print 'attributeerror'
2018-10-18
def count():
fs = []
for i in range(1, 4):
def f(x = i):
return x*x
fs.append(f)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
fs = []
for i in range(1, 4):
def f(x = i):
return x*x
fs.append(f)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
2018-10-18
import math
def is_sqr(x):
return math.sqrt(x)%1.0 == 0.0
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return math.sqrt(x)%1.0 == 0.0
print filter(is_sqr, range(1, 101))
2018-10-17
class Person(object):
def __init__(self, name, score):
self.name = name
self.score = score
def get_grade(self):
if self.score >= 90:
return 'A-优秀'
elif self.score >= 60:
return 'B-及格'
else:
return 'C-不及格'
def __init__(self, name, score):
self.name = name
self.score = score
def get_grade(self):
if self.score >= 90:
return 'A-优秀'
elif self.score >= 60:
return 'B-及格'
else:
return 'C-不及格'
2018-10-16
想了很久无奈只能这样了?
def count():
fs = []
index = []
for i in range(1, 4):
def f():
result = index[0] * index[0]
index.pop(0)
return result
fs.append(f)
index.append(i)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
def count():
fs = []
index = []
for i in range(1, 4):
def f():
result = index[0] * index[0]
index.pop(0)
return result
fs.append(f)
index.append(i)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
2018-10-12
import math
def is_sqr(x):
return str(math.sqrt(x))[-2:]=='.0'
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return str(math.sqrt(x))[-2:]=='.0'
print filter(is_sqr, range(1, 101))
2018-10-11
def cmp_ignore_case(s1, s2):
ss1= s1.lower()
ss2= s2.lower()
if ss1 > ss2:
return 1
if ss1 < ss2:
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
ss1= s1.lower()
ss2= s2.lower()
if ss1 > ss2:
return 1
if ss1 < ss2:
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2018-10-09
import math
def is_sqr(x):
if math.sqrt(x) in range(1,11):
return x
print filter(is_sqr, range(1, 101))
def is_sqr(x):
if math.sqrt(x) in range(1,11):
return x
print filter(is_sqr, range(1, 101))
2018-10-09