print [x for x in L if x % 3==0]
print [x for x in L if x%5==0 and x<=50]
print [x for x in L if x%5==0 and x<=50]
2019-09-14
print [ m*100+n*10+l for m in range(1,10) for n in range(0,10) for l in range(1,10) if m == l]
2019-09-13
print [ int(str(m)+str(n)+str(l)) for m in range(1,10) for n in range(0,10) for l in range(1,10) if m == l]
2019-09-13
def average(*args):
sum = 0.0
for i in args:
sum = sum + i
if args is ():
return 0.0
return sum/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
sum = 0.0
for i in args:
sum = sum + i
if args is ():
return 0.0
return sum/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2019-09-12
def move(n, a, b, c):
if n == 1:
print a,'-->',c
return
print a,'-->',b
move(n-1,a, b, c)
print b,'-->',c
move(4, 'A', 'B', 'C')
if n == 1:
print a,'-->',c
return
print a,'-->',b
move(n-1,a, b, c)
print b,'-->',c
move(4, 'A', 'B', 'C')
2019-09-12
for x in ['1','2','3','4','5','6','7','8','9']:
for y in ['0','1','2','3','4','5','6','7','8','9']:
if x < y:
print x + y
for y in ['0','1','2','3','4','5','6','7','8','9']:
if x < y:
print x + y
2019-09-12
L =['Adam',95.5,'Lisa',85,'Bart',59]
print (L)
print (L)
2019-09-12
def square_of_sum(L):
p = []
for i in L :
p.append(i*i)
return sum(p)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
p = []
for i in L :
p.append(i*i)
return sum(p)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2019-09-08
# -*- coding: utf-8 -*-
print '''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
print '''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
2019-09-06