d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
print d.iteritems()
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,':',v
average = sum / len(d)
print 'average', ':', average
print d.iteritems()
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,':',v
average = sum / len(d)
print 'average', ':', average
2019-09-27
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
print d.itervalues()
sum = 0.0
for x in d.itervalues():
print x
sum += x
print sum / len(d)
print d.itervalues()
sum = 0.0
for x in d.itervalues():
print x
sum += x
print sum / len(d)
2019-09-27
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
print d.itervalues()
n = 0
sum = 0.0
for x in d.itervalues():
print x
n += 1
sum += x
print sum / n
print d.itervalues()
n = 0
sum = 0.0
for x in d.itervalues():
print x
n += 1
sum += x
print sum / n
2019-09-27
L = []
x=1
while x<=100:
x=x+1
L.append(x*x)
print sum(L)
我想知道我这种和答案的区别在哪里
x=1
while x<=100:
x=x+1
L.append(x*x)
print sum(L)
我想知道我这种和答案的区别在哪里
2019-09-26
最赞回答 / 慕村小生
你原本代码没有缩进,没有缩进的话那一行就是一个代码组,一行一行的运行鸭~结果是0而且会报错改成这样:def square_of_sum(L): sum = 0 for x in L: sum = sum + x * x return sum#上面这里就是一个代码组,这样才能实现这个函数的功能print(square_of_sum([1, 2, 3, 4, 5]))#下面这一行又是一个代码组,实现的是调用函数和打印功能希望对你有帮助,想要理解更深一点可以再问
2019-09-26
最新回答 / 雫雫
第一点是第二个if循环里“continue”前应该有四个空格,这个是“if:”直接回车就能生成的,不要删除;第二是continue循环后面不用加“else”;第三点是“sum”运算应该写为“sum=sum+x”
2019-09-26
sum = 0
x = 1
n = 1
while True:
x=2**(n-1)
sum=sum+x
n+=1
if n>=21 :
break
print sum
x = 1
n = 1
while True:
x=2**(n-1)
sum=sum+x
n+=1
if n>=21 :
break
print sum
2019-09-26
sum = 0
x = 1
while True:
sum+=x
x = x + 2
if x > 100:
break
print sum
x = 1
while True:
sum+=x
x = x + 2
if x > 100:
break
print sum
2019-09-26
sum = 0
x = 1
n = 1
while True:
sum+=x
x = x + 2
n = n + 2
if n > 100:
break
print sum
x = 1
n = 1
while True:
sum+=x
x = x + 2
n = n + 2
if n > 100:
break
print sum
2019-09-26
for x in [1,2,3,4,5,6,7,8,9]:
for y in [1,2,3,4,5,6,7,8,9]:
if x<y :
print x,y
for y in [1,2,3,4,5,6,7,8,9]:
if x<y :
print x,y
2019-09-26
score = 85
if score>=90:
print 'excellent'
elif score>=80:
print 'good'
elif score>=60:
print 'passed'
else:
print 'failed'
if score>=90:
print 'excellent'
elif score>=80:
print 'good'
elif score>=60:
print 'passed'
else:
print 'failed'
2019-09-26