dict 中的 key和value 如果其中key 或者value 为字符串则要加上 '' 号 如果是数字或者字符则不需要加上 '' 号
2015-04-13
def average(*args):
if sum(args)!=0:
return float(sum(args))/len(args)
else:
return float(sum(args))
if sum(args)!=0:
return float(sum(args))/len(args)
else:
return float(sum(args))
2015-04-13
def generate_tr(name, score):
return '<tr><td>%s</td><td style="color:red">%s</td></tr>' % (name, score)
tds = [generate_tr(name,score) for name, score in d.iteritems()]
return '<tr><td>%s</td><td style="color:red">%s</td></tr>' % (name, score)
tds = [generate_tr(name,score) for name, score in d.iteritems()]
2015-04-13
感觉我这个还要简洁些,啊哈哈哈
print [x for x in range(100,1000) if str(x)[0:1]==str(x)[2:]]
print [x for x in range(100,1000) if str(x)[0:1]==str(x)[2:]]
2015-04-12
L = []
i=1
while i<=100 :
L.append(int(i*i))
i += 1
print sum(L)
i=1
while i<=100 :
L.append(int(i*i))
i += 1
print sum(L)
2015-04-11
sum = 0
x = 1
n = 1
while True:
sum += x
x=x*2
n = n+1
if n > 20:
break
print sum
x = 1
n = 1
while True:
sum += x
x=x*2
n = n+1
if n > 20:
break
print sum
2015-04-11