def square_of_sum(L):
A=[]
for item in L:
A.append(item*item)
return sum(A)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
A=[]
for item in L:
A.append(item*item)
return sum(A)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2015-05-01
for x in [m+n+k for m in "123456789" for n in "0123456789" for k in "123456789" if m==k]:
print str(x)
print str(x)
2015-04-30
t = ('a', 'b', ('A', 'B'))
print t
print t[2]
显示:
('a', 'b', ('A', 'B'))
('A', 'B')
原来内括号里的只算一个元素。
print t
print t[2]
显示:
('a', 'b', ('A', 'B'))
('A', 'B')
原来内括号里的只算一个元素。
2015-04-29
t = ('a', 'b', 'A', 'B')
print t
print t
2015-04-29
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
2015-04-29
在move(n-1,a,c,b)的print语句上卡住了,我认为应该是print a-->b,后来突然明白函数参数的位置是a,b,c,所以a-->c其实在move(n-1,a,c,b)中就是表示print a-->b
2015-04-29
def average(*args):
n = float(len(args))
if n:
return sum(args)/n
return n
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
n = float(len(args))
if n:
return sum(args)/n
return n
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2015-04-29