可以通过
sum = 0
x = 1
while x <= 100:
if (x % 2 != 0):
sum += x
x += 1
print(sum)
sum = 0
x = 1
while x <= 100:
if (x % 2 != 0):
sum += x
x += 1
print(sum)
2020-03-13
已采纳回答 / 慕瓜3463279
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }sum = 0.0for k, v in d.items(): sum = sum + v print k,':',v#这里for循环结束,多敲一行回车以表示下面的代码不在for循环内print 'average', ':', sum/len(d)
2020-03-12
最赞回答 / weixin_慕哥4300003
%s表示格化式一个对象为字符,%d代表整数,百分号后面的(key, d[key])就分别对应格式化字符串里的%s, %d。比如:"%s:%d"%("ab",3) => "ab:3"。希望有帮助
2020-03-12
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
L = d.values()
print (L)
sum = 0.0
for i in L:
sum += i
print (sum / len(L))
L = d.values()
print (L)
sum = 0.0
for i in L:
sum += i
print (sum / len(L))
2020-03-10