美文网首页
Day5-Python-列表作业-2018/7/20

Day5-Python-列表作业-2018/7/20

作者: PIECE_MAN | 来源:发表于2018-07-23 16:32 被阅读0次

1.

A = ['一','二','三']
if len(A) % 2 == 0:
    a = A[int(len(A) / 2)]
    b = A[int((len(A)) / 2 - 1)]
    print(b,a)
else:
    c = A[int(len(A) / 2)]
    print(c)

print('==========')

2.

list = [1,2,3,]
sum = 0
for x in list:
     y = int(x)
     sum += y
print(sum)
print('==============')

3.

list = [1,2,3,4,5,6,7]
for index in range(0,len(list)):
    if index % 2 != 0:
        print(list[index])

print('==============')

4.

list = [1,2,3,4,5,6,7,8,9]
for x in list:
    if x % 2 != 0:
        print(x)
print('==============')

5.

list = [1,2,3,4,5,6]
for x in list:
    x *= 2
    print(x)
print('==============')

6.

list = ['abc','123','aaa']
for index in range(0,len(list)):
    if index > 0:
        list[0] += list [index]
print(list[0])

7.

A = ['a','A','b','B','c','C']
B = []
C = []
for index in range(0,len(A)):
    if index % 2 != 0:
        B1 = A[index]
        B.append(B1)
    else:
        C1 = A[index]
        C.append(C1)
print(B,C)

8.

A = [1,2,3,4,5,6,7,8,9]
B = [0]
for index in range(0,len(A)):
    if index <= 4:
        a = A[index]
        B.append(a)
print(B)

相关文章

网友评论

      本文标题:Day5-Python-列表作业-2018/7/20

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