sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if (x+1)%2:
continue
sum+=x
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
if (x+1)%2:
continue
sum+=x
print sum
2020-01-15
sum = 0
x = 1
n = 1
while True:
sum = sum + x
n = n + 1
x = 2 ** (n-1)
if n > 20:
break
print sum 这个用幂运算的结果也成功了。看来要实现一种效果可以有多种代码表达方式
x = 1
n = 1
while True:
sum = sum + x
n = n + 1
x = 2 ** (n-1)
if n > 20:
break
print sum 这个用幂运算的结果也成功了。看来要实现一种效果可以有多种代码表达方式
2020-01-15
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for sorce in d.values():
sum += sorce
end = sum/(len(d))
print '%0.2f' % end
sum = 0.0
for sorce in d.values():
sum += sorce
end = sum/(len(d))
print '%0.2f' % end
2020-01-15
print 45678+0x12fd2
print"learn python in imooc"
print 100<99
print 0xff==255
print"learn python in imooc"
print 100<99
print 0xff==255
2020-01-14
已采纳回答 / qq_慕移动948305
你希望它输出什么结果?你是希望它输出所有奇数的和吗?此段代码 第一次循环就跳出了,因为x+1=2了 不符合循环条件了。要加一个continue,跳过后继续循环。sum = 0x = 1while x<100: sum=sum+x x = x + 1 if x%2==0: continueprint sum<...code...>
2020-01-13
最新回答 / _mango
sum打成sun了,而且既然是奇数和,应该是x=x+2sum = 0x = 1while x<100: sum=sum+x x=x+2print sum
2020-01-13