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
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59 }
def generate_tr(name, score):
if score < 60:
return '<tr><td>%s</td><td style="color:red">%s</td></tr>' % (name, score)
else:
return '<tr><td>%s</td><td>%s</td></tr>' % (name, score)
def generate_tr(name, score):
if score < 60:
return '<tr><td>%s</td><td style="color:red">%s</td></tr>' % (name, score)
else:
return '<tr><td>%s</td><td>%s</td></tr>' % (name, score)
2015-09-06
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for i in d.values():
sum = sum + i
print sum / len(d) #len(d) be noted
sum = 0.0
for i in d.values():
sum = sum + i
print sum / len(d) #len(d) be noted
2015-09-06