最新回答 / 不吃魚的laLa
因为第一个L.pop()删除了最后一个元素,即L=【'adam','lisa','bart'】,而print L.pop()中的L.pop()则删除了已更新的L的最后一位元素,并返回这个元素,因此print便将Bart打印出来了。
2018-12-28
L = ['Adam', 'Lisa', 'Bart']
a=L[2]
L[2]=L[0]
L[0]=a
print L
a=L[2]
L[2]=L[0]
L[0]=a
print L
2018-12-28
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2==0 :
continue
sum=sum+x
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2==0 :
continue
sum=sum+x
print sum
2018-12-27
sum = 0
x = 1
n = 1
while True:
sum += x
x *= 2
n += 1
if n> 20:
break
print sum
x = 1
n = 1
while True:
sum += x
x *= 2
n += 1
if n> 20:
break
print sum
2018-12-27
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key,':',d[key]
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key,':',d[key]
2018-12-27
因为是按照从上到下的顺序依次判断,当某一条件判断为T时,就直接打印结果,不再继续判断之后的条件,所以应该这样改:
age = 8
if age >= 18:
print 'adult'
elif age >= 6:
print 'teenager'
else:
print 'kid'
age = 8
if age >= 18:
print 'adult'
elif age >= 6:
print 'teenager'
else:
print 'kid'
2018-12-27
import math
def quadratic_equation(a, b, c):
X = b*b-4*a*c
if X < 0:
return false
elif X == 0:
return -b/(2*a)
else:
return ((-b)+math.sqrt(X))/(2*a), ((-b)-math.sqrt(X))/(2*a)
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
X = b*b-4*a*c
if X < 0:
return false
elif X == 0:
return -b/(2*a)
else:
return ((-b)+math.sqrt(X))/(2*a), ((-b)-math.sqrt(X))/(2*a)
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2018-12-27
L = []
n = 0
while cmp(n, 100) < 0:
n = n+1
L.append(n*n)
print sum(L)
n = 0
while cmp(n, 100) < 0:
n = n+1
L.append(n*n)
print sum(L)
2018-12-27