d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for k, v in d.iteritems():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
sum = 0.0
for k, v in d.iteritems():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
2019-12-17
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
n=0
sum = 0.0
for k, v in d.iteritems():
n=n+1
sum = sum + v
print k,':',v
print 'average', ':', sum/n
n=0
sum = 0.0
for k, v in d.iteritems():
n=n+1
sum = sum + v
print k,':',v
print 'average', ':', sum/n
2019-12-17
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
n=0
sum = 0.0
for x in d.itervalues():
n=n+1
sum=sum+x
print sum/n
n=0
sum = 0.0
for x in d.itervalues():
n=n+1
sum=sum+x
print sum/n
2019-12-17
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in enumerate(L):
print index+1, '-', name
for index, name in enumerate(L):
print index+1, '-', name
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in enumerate(L):
index=index+1
print index, '-', name
for index, name in enumerate(L):
index=index+1
print index, '-', name
def average(*args):
if len(args)==0:
return 0.0
else :
return sum(args)*1.0/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
if len(args)==0:
return 0.0
else :
return sum(args)*1.0/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2019-12-17
def move(n,a,b,c):
x=1
y=1
if n<0:
print ('n must not zero')
else:
while n>1 and x<n:
x = x + 1
print a,'-->',b
print a,'-->',c
while n>1 and y<n:
y = y + 1
print b,'-->',c
move(4, 'A', 'B', 'C')
x=1
y=1
if n<0:
print ('n must not zero')
else:
while n>1 and x<n:
x = x + 1
print a,'-->',b
print a,'-->',c
while n>1 and y<n:
y = y + 1
print b,'-->',c
move(4, 'A', 'B', 'C')
2019-12-17
def move(n,a,b,c):
x=1
y=1
if n<0:
print ('n must not zero')
else:
while n>1 and x<n:
x = x + 1
print a,'-->',b
print a,'-->',c
while n>1 and y<n:
y = y + 1
print b,'-->',c
move(4, 'A', 'B', 'C')
x=1
y=1
if n<0:
print ('n must not zero')
else:
while n>1 and x<n:
x = x + 1
print a,'-->',b
print a,'-->',c
while n>1 and y<n:
y = y + 1
print b,'-->',c
move(4, 'A', 'B', 'C')
2019-12-17
最新回答 / 慕运维2238537
正确代码:sum = 0x = 0while True: x = x + 1 if x%2==0: continue sum=sum+x if x >= 99: breakprint sum两点错了,第一,x%2应该是等于0,continue是直接跳到while 条件判断,跳过sum=sum+x了。第二,if x>100,那个时候,会多计算一次101,所以x>=99或者x==99都行
2019-12-17