print [(m*100)+(n*10)+k for m in range(1,10) for n in range(0,10) for k in range(0,10) if m==k]
2015-08-21
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for index,number in enumerate(d.values()):
sum+=number
print sum/(index+1)
sum = 0.0
for index,number in enumerate(d.values()):
sum+=number
print sum/(index+1)
2015-08-20
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for index,number in enumerate(d.values()):
sum+=number
print sum/index
sum = 0.0
for index,number in enumerate(d.values()):
sum+=number
print sum/index
2015-08-20
def greet(s='world'):
print 'Hello,',s
greet()
greet('name')
print 'Hello,',s
greet()
greet('name')
2015-08-20
想了一段时间
理解:
设为两层,则为A-->B,B--C,B-->C
改变参数位置,让它n==1时,符合,就行了
def move(n, a, b, c):
if n==1:
print a,'-->',c
return
move(n-1,a,c,b)
print a,'-->',c
move(n-1,b,a,c)
move(4, 'A', 'B', 'C')
理解:
设为两层,则为A-->B,B--C,B-->C
改变参数位置,让它n==1时,符合,就行了
def move(n, a, b, c):
if n==1:
print a,'-->',c
return
move(n-1,a,c,b)
print a,'-->',c
move(n-1,b,a,c)
move(4, 'A', 'B', 'C')
2015-08-20
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for name in d:
print name,':',d[name]
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for name in d:
print name,':',d[name]
2015-08-20