L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(2)
L.pop(2)
print L
第一个是去掉了Paul 然后数组变成3个人 Bart的位置在2 所以再执行一次就好了
L.pop(2)
L.pop(2)
print L
第一个是去掉了Paul 然后数组变成3个人 Bart的位置在2 所以再执行一次就好了
2015-03-30
def average(*args):
sum = 0.0
if len(args) == 0:
return sum
else:
for x in args:
sum = sum + x
return sum / len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
我去,,sum = 0 打印是一个整数,一直提示不对,还在想那里有问题,原来还是精度的问题
sum = 0.0
if len(args) == 0:
return sum
else:
for x in args:
sum = sum + x
return sum / len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
我去,,sum = 0 打印是一个整数,一直提示不对,还在想那里有问题,原来还是精度的问题
2015-03-30
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for name in L:
if name in s:
s.remove(name)
else:
s.add(name)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for name in L:
if name in s:
s.remove(name)
else:
s.add(name)
print s
2015-03-30
s = 'Python was started in 1989 by \"Guido\".\nPython is free and easy to learn.'
print s
print s
2015-03-29
def square_of_sum(L):
if L==[]:
return 0
else:
sum=0
for x in L:
sum+=x*x
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
if L==[]:
return 0
else:
sum=0
for x in L:
sum+=x*x
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2015-03-29
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
2015-03-29
for x in range(1,10):#0~9
for y in range(1,10):#0~9
if x < y:
print x * 10 + y
for y in range(1,10):#0~9
if x < y:
print x * 10 + y
2015-03-29