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
for x in [ 1,2,3,4,5,6,7,8,9 ]:
for y in [ 1,2,3,4,5,6,7,8,9 ]:
if x<y:
print x*10+y
因为事先明显知道整十的数不满足要求,可以不用考虑,忽略y中的0,速度更快
for y in [ 1,2,3,4,5,6,7,8,9 ]:
if x<y:
print x*10+y
因为事先明显知道整十的数不满足要求,可以不用考虑,忽略y中的0,速度更快
2015-03-29
sum = 0
x = 99
while x>=1:
sum+=x
x = x - 2
print sum
这种方式虽然不是标准答案,但是貌似更简单
x = 99
while x>=1:
sum+=x
x = x - 2
print sum
这种方式虽然不是标准答案,但是貌似更简单
2015-03-29
sum = 0
x = 1
n = 1
while n<=20:
sum+=x
x*=2
n+=1
print sum
x = 1
n = 1
while n<=20:
sum+=x
x*=2
n+=1
print sum
2015-03-29