d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'Adam:',d['Adam']
print 'Lisa:',d.get('Lisa')
if 'Bart' in d:
print 'Bart:',d["Bart"]
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'Adam:',d['Adam']
print 'Lisa:',d.get('Lisa')
if 'Bart' in d:
print 'Bart:',d["Bart"]
2015-09-08
print [int(x+y+j) for x in '123456789' for y in '0123456789' for j in '123456789' if x==j]
2015-09-08
def generate_tr(name, score):
if score<60:
tdscore='<td style="color:red">%s' % score
else:
tdscore='<td>%s' % score
return '<tr><td>%s</td>%s</td></tr>' % (name, tdscore)
if score<60:
tdscore='<td style="color:red">%s' % score
else:
tdscore='<td>%s' % score
return '<tr><td>%s</td>%s</td></tr>' % (name, tdscore)
2015-09-08
s = 'Python was started in 1989 by "Guido".\nPython is free and easy to learn.'
print s
print s
2015-09-08
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for name in s:
print name[0],":",name[1]
for name in s:
print name[0],":",name[1]
2015-09-07
L = [75, 92, 59, 68]
sum = 0.0
for score in L:
sum += score
print sum / 4.0
sum = 0.0
for score in L:
sum += score
print sum / 4.0
2015-09-07
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for x in d.itervalues():
sum+=x
print sum/len(d)
sum = 0.0
for x in d.itervalues():
sum+=x
print sum/len(d)
2015-09-07
def average(*args):
if len(args)>0:
aver=float(sum(args))/len(args)
return aver
else :
return float(0)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
if len(args)>0:
aver=float(sum(args))/len(args)
return aver
else :
return float(0)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2015-09-07
def square_of_sum(L):
A=0
for x in L:
A+=x*x
return A
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
A=0
for x in L:
A+=x*x
return A
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2015-09-07
我没有按格式写,提交成功了:
for x in range(10,100):
if x/10 < x%10:
print x
for x in range(10,100):
if x/10 < x%10:
print x
2015-09-07