Bootstrap

python练习(2)

NP56 列表解析

a=[]
for i in range(0,10):
    a.append(i)
print(a)

NP57 格式化清单

list=['apple', 'ice cream', 'watermelon', 'chips', 'hotdogs', 'hotpot']
while list:
    list.pop()
    print(list)

NP59 提前结束的循环

list=[3, 45, 9, 8, 12, 89, 103, 42, 54, 79]

a=int(input())
for i in list:
    if i==a:
        break
    print(i)

NP60 跳过列表的某个元素

for i in range(1,16):
    if i == 13:
        continue
    print(i,end=' ')

NP61 牛牛的矩阵相加

list=[[1,2,3],[4,5,6],[7,8,9]]
n=int(input())
for i in range(3):
    for j in range(3):
        list[i][j]*=n
print(list)

NP62 运动会双人项目

a=input()
b=input()
print((a,b))

NP63 修改报名名单

a=('Niuniu','Niumei')
print(a)
try:
    a[1] = 'Niukele'
except:
    print('The entry form cannot be modified!')

NP64 输出前三同学的成绩

a=input().split()
a=tuple(a[:3])
print(a)

NP65 名单中出现过的人

a=['Tom', 'Tony', 'Allen', 'Cydin', 'Lucy', 'Anna']
a= tuple(a)
print(a)
name=input()
if name in a:
    print('Congratulations!')
else:
    print('What a pity!')

NP66 增加元组的长度

a=tuple(range(1,6))
print(a)
print(len(a))
b=tuple(range(6,11))
a=a+b
print(a)
print(len(a))

NP72 生成字典

key=input().split()
value=input().split()
key_value=dict(zip(key,value))
print(key_value)

NP73 查字典

a={'a': ['apple', 'abandon', &
;