这节说真的,有点难理解的。一上来就是有点复杂的封装函数。。还好我有点小基础。。
#-*- coding:utf-8 -*-
def square_of_sum(L):
y = 0
for x in L:
x = x * x #平方
y = y + x #存储x
return y
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
#-*- coding:utf-8 -*-
def square_of_sum(L):
y = 0
for x in L:
x = x * x #平方
y = y + x #存储x
return y
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2018-04-28
#-*- coding:utf-8 -*-
L = set([])
x = 1
while x <= 100: #只到100
print x,'*',x,'=',x * x #显示每个结果
L.add(x*x) #插入1X1 2X2 这玩意
x = x + 1 #1-2-3-4-5-6-7-8-9……递增
SB = sum(L) #求和
print SB #显示出来
L = set([])
x = 1
while x <= 100: #只到100
print x,'*',x,'=',x * x #显示每个结果
L.add(x*x) #插入1X1 2X2 这玩意
x = x + 1 #1-2-3-4-5-6-7-8-9……递增
SB = sum(L) #求和
print SB #显示出来
2018-04-28
L = range(1, 101)
def function(scope,mol):
for x in scope:
if x%mol==0:
return scope[x-1::mol]
print function(L,3)
print function(L[:50],5)
def function(scope,mol):
for x in scope:
if x%mol==0:
return scope[x-1::mol]
print function(L,3)
print function(L[:50],5)
2018-04-28
终于我也有一个不一样的答案(手动滑稽):
print [int(x+y+z) for x in '123456789'for y in '0123456789'for z in '0123456789' if x==z]
print [int(x+y+z) for x in '123456789'for y in '0123456789'for z in '0123456789' if x==z]
2018-04-28
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key,":",d[key]
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key,":",d[key]
2018-04-28
拜托认为是34不是100项的,
麻烦动手百度下等差数列求和公式,
楼下那位34的大哥真正算错的是你
而不是前面那位兄弟,
搞得我以为高数白学了。
麻烦动手百度下等差数列求和公式,
楼下那位34的大哥真正算错的是你
而不是前面那位兄弟,
搞得我以为高数白学了。
2018-04-27