记录牛客刷题篇
很多细小知识点能得到及时复习,难得的Python入门题库,非常适合入门的小伙伴练习哦
某公司在面试结束后,创建了一个依次包含字符串 'Allen' 和 'Tom' 的列表offer_list,作为通过面试的名单。
请你依次对列表中的名字发送类似 'Allen, you have passed our interview and will soon become a member of our company.' 的句子。
但由于Tom有了其他的选择,没有确认这个offer,HR选择了正好能够确认这个offer的Andy,所以请把列表offer_list中 'Tom' 的名字换成 'Andy' ,
再依次发送类似 'Andy, welcome to join us!' 的句子。
offer_list = ['Allen', 'Tom']
for i in offer_list:
print(f'{i}, you have passed our interview and will soon become a member of our company.')
offer_list[1] = 'Andy'
for j in offer_list:
print(f'{j}, welcome to join us!')
运行
Allen, you have passed our interview and will soon become a member of our company.
Tom, you have passed our interview and will soon become a member of our company.
Allen, welcome to join us!
Andy, welcome to join us!
为庆祝驼瑞驰在牛爱网找到合适的对象,所以驼瑞驰创建了一个依次包含字符串 'Niuniu' 和 'Niu Ke Le' 的列表guest_list,作为庆祝派对的邀请名单。
请你依次对列表中的名字发送类似'Niuniu, do you want to come to my celebration party?'的句子。
驼瑞驰的好朋友牛牛、GURR哥和LOLO姐也正好有空,所以请使用insert()方法把字符串'GURR'插入到列表guest_list的开头,
再使用insert()方法把字符串'Niumei'插入到字符串'Niu Ke Le'的前面,再使用append()方法把字符串'LOLO'插入到列表guest_list的最后,
再依次发送类似'Niuniu, thank you for coming to my celebration party!'的句子。
guest_list = ['Niuniu', 'Niu Ke Le']
for i in guest_list:
print(f'{i}, do you want to come to my celebration party?')
print()
guest_list.insert(0, 'GURR')
guest_list.insert(2, 'Niumei')
guest_list.append('LOLO')
for j in guest_list:
print(f'{j}, thank you for coming to my celebration party!')
运行
Niuniu, do you want to come to my celebration party?
Niu Ke Le, do you want to come to my celebration party?
GURR, thank you for coming to my celebration party!
Niuniu, thank you for coming to my celebration party!
Niumei, thank you for coming to my celebration party!
Niu Ke Le, thank you for coming to my celebration party!
LOLO, thank you for coming to my celebration party!
company_list = ['Alibaba', 'Baidu', 'Tencent', 'MeiTuan', 'JD']
for i in company_list:
print(f'Hello {i}, here is my resume!')
del company_list[0]
company_list.pop()
company_list.pop()
company_list.remove('Tencent')
print()
for j in company_list:
print(f'{j}, thank you for passing my resume. I will attend the interview on time!')
运行
Hello Alibaba, here is my resume!
Hello Baidu, here is my resume!
Hello Tencent, here is my resume!
Hello MeiTuan, here is my resume!
Hello JD, here is my resume!
Baidu, thank you for passing my resume. I will attend the interview on time!
my_list = ['P', 'y', 't', 'h', 'o', 'n']
print('Here is the original list:')
print(my_list)
print()
print('The result of a temporary reverse order:')
print(sorted(my_list,reverse=True))
print()
print('Here is the original list again:')
print(my_list)
my_list.sort(reverse=True)
print()
print('The list was changed to:')
print(my_list)
my_list.reverse()
print()
print('The list was changed to:')
print(my_list)
运行
Here is the original list:
['P', 'y', 't', 'h', 'o', 'n']
The result of a temporary reverse order:
['y', 't', 'o', 'n', 'h', 'P']
Here is the original list again:
['P', 'y', 't', 'h', 'o', 'n']
The list was changed to:
['y', 't', 'o', 'n', 'h', 'P']
The list was changed to:
['P', 'h', 'n', 'o', 't', 'y']
使用一个 for 循环 或 while 循环 打印[1, 20]中的所有整数(一行一个数字)。
for i in range(1,21):
print(i)
运行
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
牛牛有一个name = ['Niumei', 'YOLO', 'Niu Ke Le', 'Mona'] 记录了他最好的朋友们的名字,请创建一个二维列表friends,使用append函数将name添加到friends的第一行。
假如Niumei最喜欢吃pizza,最喜欢数字3,YOLO最喜欢吃fish, 最喜欢数字6,Niu Ke Le最喜欢吃potato,最喜欢数字0,Mona最喜欢吃beef,最喜欢数字3。
请再次创建一个列表food依次记录朋友们最喜欢吃的食物,并将创建好的列表使用append函数添加到friends的第二行;
然后再创建一个列表number依次记录朋友们最喜欢的颜色,并将创建好的列表使用append函数添加到friends的第三行。
这样friends就是一个二维list,使用print函数直接打印这个二维list。
name = ['Niumei', 'YOLO', 'Niu Ke Le', 'Mona']
friends = []
friends.append(name)
food = ['pizza', 'fish', 'potato', 'beef']
friends.append(food)
number = [3, 6, 0, 3]
friends.append(number)
print(friends)
运行
[['Niumei', 'YOLO', 'Niu Ke Le', 'Mona'], ['pizza', 'fish', 'potato', 'beef'], [3, 6, 0, 3]]
陆续将更新循环语句篇、条件语句篇、元组篇、字典篇、函数篇、综合实践篇
本系列内容非必要不提供代码块解读注释,可直接看文章在自己的编译器做题
此文仅为记录做题,非最优解法,对任何步骤有不懂的,欢迎交流!