d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for k, v in d.items():
sum = sum + v
print k+':'+str(v)
average = sum/len(d)
print 'average', ':', average
sum = 0.0
for k, v in d.items():
sum = sum + v
print k+':'+str(v)
average = sum/len(d)
print 'average', ':', average
2018-05-06
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for i in d.itervalues():#d.values()
sum+=i
print sum/len(d)
sum = 0.0
for i in d.itervalues():#d.values()
sum+=i
print sum/len(d)
2018-05-06
我想问一下 a = True
print a and 'a=T' or 'a=F' 为什么不直接返回True
print a and 'a=T' or 'a=F' 为什么不直接返回True
2018-05-06
参考别人的
if args:
return float(sum(args)) / len(args)
else:
return 0.0
if args:
return float(sum(args)) / len(args)
else:
return 0.0
2018-05-05
笨方法,分享一下
n = len(args)
if n == 0:
return 0.0
su = 0.0
for num in args:
su = su + int(num)
return su / n
n = len(args)
if n == 0:
return 0.0
su = 0.0
for num in args:
su = su + int(num)
return su / n
2018-05-05
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in zip(range(1,len(L)+1),L):
print index, '-', name
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in enumerate(L):
print index+1, '-', name
for index, name in zip(range(1,len(L)+1),L):
print index, '-', name
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in enumerate(L):
print index+1, '-', name