L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(2)
'Paul'
L.pop(2)
'Bart'
print L
L.pop(2)
'Paul'
L.pop(2)
'Bart'
print L
2019-05-20
L = range(1, 101)
print L[0:10]
print L[2:101:3]
print L[4:50:5]
print L[0:10]
print L[2:101:3]
print L[4:50:5]
2019-05-19
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in enumerate(L):
print index + 1, '-', name
for index, name in enumerate(L):
print index + 1, '-', name
程序是有执行顺序的,自上而下执行代码。
当L.pop(2)后剩下的只有['Adam', 'Lisa', 'Bart']
此时的'Bart'元素位于下标为2的位置,或者为最后一个的位置
所以解法有两种:
1.
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(2) -Paul
L.pop(2) -Bart
print L -['Adam', 'Lisa']
2.
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(2) -Paul
L.pop(-1) -Bart
print L -['Adam', 'Lisa']
当L.pop(2)后剩下的只有['Adam', 'Lisa', 'Bart']
此时的'Bart'元素位于下标为2的位置,或者为最后一个的位置
所以解法有两种:
1.
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(2) -Paul
L.pop(2) -Bart
print L -['Adam', 'Lisa']
2.
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(2) -Paul
L.pop(-1) -Bart
print L -['Adam', 'Lisa']
2019-05-17
首先将a柱上的(n-1)个放在b柱上,然后将最大的那个放到c柱上,最后再将b柱上的(n-1)个放到c柱上
代码如下:
def move(n, a, b, c):
if n == 1:
print a, '-->' , c
move(n-1,a,c,b)
move(1,a,b,c)
move(n-1,b,a,c)
代码如下:
def move(n, a, b, c):
if n == 1:
print a, '-->' , c
move(n-1,a,c,b)
move(1,a,b,c)
move(n-1,b,a,c)
2019-05-17
def square_of_sum(L):
L1=[]
for name in L:
L1.append(name * name)
return sum(L1)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
L1=[]
for name in L:
L1.append(name * name)
return sum(L1)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2019-05-16
sum = ['A','B','C','D']
sum2 = ['E','F','G','H']
sum3 = ['a','b','c','d']
for x in sum:
for y in sum2:
for z in sum3:
print x + y + z
sum2 = ['E','F','G','H']
sum3 = ['a','b','c','d']
for x in sum:
for y in sum2:
for z in sum3:
print x + y + z
2019-05-15
sum = 0
x = 0
while True:
x = x + 1
if x % 2 == 0:
continue
if x > 100:
break
sum = sum + x
print sum
x = 0
while True:
x = x + 1
if x % 2 == 0:
continue
if x > 100:
break
sum = sum + x
print sum
2019-05-15