print a + b
print sorted(L) # 返回新的list
print a[::-1] # 切片的知识点
print ",".join([str(x) for x in a]) # 列表解析式和join方法,参数是str instance
print a[::2]
def prime(n):
if n == 2:
return True
for i in range(2, n):
if n % i ==0:
return False
return True
print [x for x in range(2, 100) if prime(x)]
L = sorted(L)
length = len(L)/2.0
if len(L) % 2 ==0:
print (L[int(length-1]+L[int(length)])/2.0
else:
print L[int(length)]
print a*b, (a+b)*2
def lcm(a, b):
if a >b:
greater = a
else:
greater = b
while True:
if greater % a ==0 and greater % b ==0:
lcm = greater
break
greater +=1
return lcm
print [x for x in range(1,min(a,b)) if a % x ==0 and b % x ==0][-1]
sum_i = 1
count = 0
for i in L:
sum_i *= i
s = str(sum)[::-1]
for i in s:
if i == '0':
count +=1
else:
break
print count
sum_i = 1
count = 0
for i in L:
sum_i *= i
s = str(sum)[::-1]
for i in s:
if i !='0' and int(i) % 2 ==0:
print 0
elif i !='0' and int(i) % 2 !=0:
print 1