最新回答 / 清波
不管list 中是什么元素, 想要删除的话, 都可以使用 L.pop(index) 来删除, 就比如说题主的例子:L=['我','爱','吃饭']L.pop(1) ## 即可删除
2016-04-11
我们知道等差数列公式是:Sn=n(a1+an)/2
但是这里不知道an是多少,所以计算an的公式:an=a1+(n-1)d
x100 = x1+(n-1)*d
s = n*(x1+x100)/2
最后就可以得出Sn
但是这里不知道an是多少,所以计算an的公式:an=a1+(n-1)d
x100 = x1+(n-1)*d
s = n*(x1+x100)/2
最后就可以得出Sn
2016-04-11
sum = 0
x = 1
n = 1
while True:
sum+=x
x=2**n
n=n+1
if n > 20:
break
print sum
x = 1
n = 1
while True:
sum+=x
x=2**n
n=n+1
if n > 20:
break
print sum
2016-04-11
sum = 0
x = 1
while x < 100:
print x
x=x+2
sum+=x
print sum
x = 1
while x < 100:
print x
x=x+2
sum+=x
print sum
2016-04-11
def test_str(*x):
for a in x:
if not isinstance(a,str):
print a,'not str'
continue
print a.upper()
for a in x:
if not isinstance(a,str):
print a,'not str'
continue
print a.upper()
已采纳回答 / 清波
。。。 还真是看了一段时间才看出来,看来我跟题主一样,被日常思维给误解了,不废话先说出正确代码:<...code...>只是把 if 换成了 while, if 是判断语句嘛,所以题主的代码就执行了一次。。结果自然就是2 了。
2016-04-10
def move(n, a, b, c):
if n==0 :
return;
move(n-1,a,c,b)
print a,'-->',c
move(n-1,b,a,c)
move(4, 'a', 'b', 'c')
if n==0 :
return;
move(n-1,a,c,b)
print a,'-->',c
move(n-1,b,a,c)
move(4, 'a', 'b', 'c')
2016-04-10