美文网首页
Day6作业

Day6作业

作者: 巫岷俊 | 来源:发表于2018-09-11 20:09 被阅读0次

1.已知一个列表,求列表中心元素。

def center(list):
len1=len(list)
if len1%2 ==0:
print(list[int((len1-1)//2)],list[int((len1-1)//2+1)])
else:
print(list[int((len1-1)//2)])

center([12,12,44,66,98])

2.已知一个列表,求所有元素和。

def add(list):
s = 0
for x in list:
s=s+x
print(s)

def ji(list):
print(list[1:-1:2])

相关文章

网友评论

      本文标题:Day6作业

      本文链接:https://www.haomeiwen.com/subject/runegftx.html