def square_of_sum(L):
s=[]
for i in L:
x = i*i
s.append(x)
return sum(s)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
s=[]
for i in L:
x = i*i
s.append(x)
return sum(s)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2020-03-05
居然用了字符串
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+y
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+y
2020-03-05
d = {'Adam': 95,
'Lisa': 85,
'bart': 59
}
d.setdefault('Paul',75)
print(d)
'Lisa': 85,
'bart': 59
}
d.setdefault('Paul',75)
print(d)
2020-03-05
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for k, v in d.iteritems():
a = len(k)
sum = sum + v
sum1 = sum/a
print(k,':',v)
print 'average', ':', sum1
sum = 0.0
for k, v in d.iteritems():
a = len(k)
sum = sum + v
sum1 = sum/a
print(k,':',v)
print 'average', ':', sum1
2020-03-05
为什么我没用上n (哭.jpg)
sum = 0
x = 1
n = 1
while True:
sum=2**(x-1)+sum
x=x+1
if x>20:
break
print sum
sum = 0
x = 1
n = 1
while True:
sum=2**(x-1)+sum
x=x+1
if x>20:
break
print sum
2020-03-05
最新回答 / 慕运维5384406
set 就是结合了列表和字典的优点,首先是不存储value,存储空间相对较小,第二个是里面是无序的,而且不重复,搜索的时候比列表快(元素多的时候)
2020-03-05
L = ['Adam', 'Lisa', 'Bart']
X=L[0]
L[0]=L[-1]
L[-1]=X
print L
X=L[0]
L[0]=L[-1]
L[-1]=X
print L
2020-03-05
已采纳回答 / 慕容8165904
先理解两种情况,一是只有一个积木,二是有两个积木。一个积木时,print a,'-->',c 这个比较好理解,直接把a上的积木移到c上。这时,前四行的代码可以理解了,剩下三行的代码,可以理解为两块积木的情况。两块积木时,先把a移到b,再把a移到c,最后把b移到c。一定要先理解规则。此时,根据n==1时的定义,move(n, a, b, c)中,a移到c,也就是第二个元素移动到第四个元素。所以a移动到b,表达为move(n - 1 , a , c , b),然后,a移动到c,表达为move(1 , a...
2020-03-04
print 45678 + 0x12fd2
print 'Learn Python in imooc'
print 100 < 99
print 0xff == 255
print 'Learn Python in imooc'
print 100 < 99
print 0xff == 255
2020-03-04
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
2020-03-04
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x in s:
print(x[0]+':'+str(x[1]))
for x in s:
print(x[0]+':'+str(x[1]))
2020-03-04