def square_of_sum(L):
lst=[]
for i in L:
lst.append(i*i)
return sum(lst)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
lst=[]
for i in L:
lst.append(i*i)
return sum(lst)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2015-06-10
L = []
for x in range(1,10):
for y in range(10):
for z in range(1,10):
if(x == z):
L.append(100*x + 10*y +z)
print L
for x in range(1,10):
for y in range(10):
for z in range(1,10):
if(x == z):
L.append(100*x + 10*y +z)
print L
2015-06-10
被自己蠢哭了,写的代码完全是正确的,最后没办法通过。原因是: print a, '-->', c
这里的剪头是两个减号!!!
这里的剪头是两个减号!!!
2015-06-10
已采纳回答 / Perona
x 这个变量是在 for 循环中定义的,意思是,依次取出L中的每一个元素,并把元素赋值给x,然后执行for循环体(就是缩进的代码块)。有兴趣可以去看Python源码剖析~~~
2015-06-09
print [m+n*10+j*100 for m in range(1,10) for n in range(0,10) for j in range(0,10) if m==j]
2015-06-09
def square_of_sum(L):
s = 0
n = 1
for x in L:
s = s + x*x
n = n + 1
while n > len(L):
return s
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
s = 0
n = 1
for x in L:
s = s + x*x
n = n + 1
while n > len(L):
return s
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2015-06-09
L = []
x = 1
while x<101:
L.append(x*x)
x = x + 1
print sum(L)
x = 1
while x<101:
L.append(x*x)
x = x + 1
print sum(L)
2015-06-09
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
2015-06-09
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x in s:
print x[0],":",x[1]
for x in s:
print x[0],":",x[1]
2015-06-09