import sys
reload(sys)
sys.setdefaultencoding('utf8')
我按照参考代码输入,仍然有误,百度了以后添加以上几行代码才成功了
reload(sys)
sys.setdefaultencoding('utf8')
我按照参考代码输入,仍然有误,百度了以后添加以上几行代码才成功了
2019-08-12
L = [75, 92, 59, 68]
sum = 0.0
for x in range(4):
sum+= L[x]
print sum / 4
sum = 0.0
for x in range(4):
sum+= L[x]
print sum / 4
2019-08-12
x1 = 1
d = 3
n = 100
x100 = x1 + (n-1) * d
s = 0
for i in range(100):
s = s + (x1 + d * i)
print s
d = 3
n = 100
x100 = x1 + (n-1) * d
s = 0
for i in range(100):
s = s + (x1 + d * i)
print s
2019-08-10
sum = 0
x = 1
n = 1
while True:
x = 2**(n-1)
n += 1
sum += x
if n > 20:
break
print sum
x = 1
n = 1
while True:
x = 2**(n-1)
n += 1
sum += x
if n > 20:
break
print sum
2019-08-08
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for i in L:
if i in s:
s.remove(i)
else:
s.add(i)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for i in L:
if i in s:
s.remove(i)
else:
s.add(i)
print s
2019-08-08
小白入门,自从进入 循环语 这章节(5章)开始就有点感觉脑力不够用了。
到底还是没有适应编程语言习惯啊。
感觉答案出来的代码真的是脑洞大开,但是对编程语言来说又是那么的普通合乎常理。
到底还是没有适应编程语言习惯啊。
感觉答案出来的代码真的是脑洞大开,但是对编程语言来说又是那么的普通合乎常理。
2019-08-07
sum = 0
x = 1
n = 1
while True:
sum = sum + x
x = x * 2
n = n + 1
if n > 20:
print sum
这样好像也可以
x = 1
n = 1
while True:
sum = sum + x
x = x * 2
n = n + 1
if n > 20:
print sum
这样好像也可以
2019-08-07
i=1
sum=0
L = [i]
for i in range(0,100):
i=i+1
sum=sum+i*i
print sum
sum=0
L = [i]
for i in range(0,100):
i=i+1
sum=sum+i*i
print sum
2019-08-07
提供2种解法,后一种才是使用continue
sum = 0
x = 1
while True:
if x%2==1:
sum = sum + x
x = x + 1
if x > 100:
break
print sum
sum = 0
x = 1
while True:
if x%2!=1:
x = x + 1
continue;
sum = sum + x
x = x + 1;
if x > 99:
break
print sum
sum = 0
x = 1
while True:
if x%2==1:
sum = sum + x
x = x + 1
if x > 100:
break
print sum
sum = 0
x = 1
while True:
if x%2!=1:
x = x + 1
continue;
sum = sum + x
x = x + 1;
if x > 99:
break
print sum
2019-08-07