d = { 'Adam': 95.0, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
print sum(d.values())/len(d.values())
print sum(d.values())/len(d.values())
2015-06-06
def firstCharUpper(s):
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2015-06-06
html表格标签
<table>
<tr>
<td></td>
</tr>
</table>
table的结构
<tr></tr>代表一行
<td></td>代表一列
<table>
<tr>
<td></td>
</tr>
</table>
table的结构
<tr></tr>代表一行
<td></td>代表一列
2015-06-05
这样也可以
for x in [ '1','2','3','4','5','6','7','8','9' ]:
for y in [ '1','2','3','4','5','6','7','8','9' ]:
if x<y:
print x+y
for x in [ '1','2','3','4','5','6','7','8','9' ]:
for y in [ '1','2','3','4','5','6','7','8','9' ]:
if x<y:
print x+y
2015-06-05
def move(n, a, b, c):
if n==1:
print a,'-->',c
else:
move(n-1,a,c,b)
print a,'-->',c
move(n-1,b,a,c)
move(4, 'a', 'b', 'c')
if n==1:
print a,'-->',c
else:
move(n-1,a,c,b)
print a,'-->',c
move(n-1,b,a,c)
move(4, 'a', 'b', 'c')
2015-06-05
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
i = 0
for name in L:
if L[i] in s:
s.remove(L[i])
else:
s.add(L[i])
i = i + 1
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
i = 0
for name in L:
if L[i] in s:
s.remove(L[i])
else:
s.add(L[i])
i = i + 1
print s
2015-06-05
【这一系列条件判断会从上到下依次判断,如果某个判断为 True,执行完对应的代码块,后面的条件判断就直接忽略,不再执行了。】好像很多人都没注意到这一句然后自以为是地认为答案有问题……
2015-06-05
def move(n, a, b, c):
if n==1:
print a+'-->'+c
else:
move(n-1,a,c,b)
move(1,a,b,c)
move(n-1,b,a,c)
move(4, 'A', 'B', 'C')
if n==1:
print a+'-->'+c
else:
move(n-1,a,c,b)
move(1,a,b,c)
move(n-1,b,a,c)
move(4, 'A', 'B', 'C')
2015-06-04
print r'''"To be, or not to be": that is the question.
Whether it's nobler in the mind to suffer.'''
Whether it's nobler in the mind to suffer.'''
2015-06-04