"""基础题"""
lst1 = [1, 3, 4, 5, 7, 10, 14]
for num in lst1:
if num % 2 != 0:
print(num)
print('-' * 40)
lst2 = [2, 5, 9, 15, 18, 20, 21]
for num in lst2:
if num % 3 == 0 and num % 2 != 0:
print(num)
print('-' * 40)
lst3 = [2, 5, 9, 15, 18, 20, 21]
count = 0
for num in lst3:
if num % 2 == 0:
count += num
print(count)
print('-' * 40)
lst4 = [2, 5, 9, 15, 18, 20, 21, 128, 256, 512, 1024]
count = 0
for num in lst4:
if num // 10 % 10 == 1:
count += 1
print(count)
print('-' * 40)
lst5 = [2, 5, 9, 15, 18, 20, 21, 128, 256, 512, 1024]
lst6 = []
for num in range(len(lst5)):
if num % 2 != 0:
lst6.append(lst5[num])
print(lst6)
print('-' * 40)
lst7 = [2, 5, 9, 15, 18, 20, 21]
for i in range(len(lst7)):
lst7[i] *= 2
print(lst7)
print('-' * 40)
lst8 = [2, 5, 9, 15, 18, 20, 21, 33]
lst9 = []
length = len(lst8)
if length == 0:
print('该列表是空列表')
elif length % 2 != 0:
num_index1 = int(length * 0.5 - 0.5)
print(f'中心元素为:{lst8[num_index1]}')
else:
num_index2 = int(length * 0.5 - 1)
num_index3 = int(length * 0.5)
print(f'中心元素为:{lst8[num_index2]}和{lst8[num_index3]}')
print('-' * 40)
"""进阶题"""
scores = [45, 60, 89, 30, 12, 59, 99, 80, 71, 66]
lst10 = []
for score in scores:
if score >= 60:
lst10.append(score)
print(lst10)
print('-' * 40)
names = ['小明', '张三', '李四', '张三', '张三', '小明', '王五', '王五']
lst11 = []
for name in names:
if name not in lst11:
lst11.append(name)
print(lst11)
print('-' * 40)
lst12 = [45, 60, 89, 30, 12, 59, 99, 80, 71, 66]
lst13 = [-1]
for num in lst12:
if num > lst13[0]:
lst13[0] = num
print(lst13[0])
print('-' * 40)
lst14 = [10, 23, 39, 41, 52, 55, 80]
lst15 = [9, 10, 38, 55, 70]
new_lst = []
while True:
num1 = lst14.pop(0)
num2 = lst15.pop(0)
if num1 < num2:
new_lst.append(num1)
lst15.insert(0, num2)
else:
new_lst.append(num2)
lst14.insert(0, num1)
if lst14 == [] or lst15 == []:
new_lst += lst14 + lst15
break
print(new_lst)
print('-' * 40, 'next', '-' * 40)
lst17 = [10, 23, 45, 67, 91]
num = eval(input('请输入一个数字:'))
if num > lst17[-1]:
lst17.append(num)
else:
for i in range(len(lst17)):
if num < lst17[i]:
lst17.insert(i, num)
break
print(lst17)
print('-' * 40, 'next', '-' * 40)