发布时间:2022-12-07 14:00
记录牛客刷题篇
很多细小知识点能得到及时复习,难得的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]]
陆续将更新循环语句篇、条件语句篇、元组篇、字典篇、函数篇、综合实践篇
本系列内容非必要不提供代码块解读注释,可直接看文章在自己的编译器做题
此文仅为记录做题,非最优解法,对任何步骤有不懂的,欢迎交流!
基于Android Studio经典蓝牙APP---继上一次的完善版
Java私活200元,完成JavaSwing学生成绩管理系统(三)
重磅!原清华副校长任职南科大校长:他考研三次,读博七年,想做科研人偶像...
【开源】DA14580-SPI教程——疯壳·ARM双处理器开发板系列
最适合新手的python刷题网站_有的人能轻松学会Python编程,不是基础好,而是有了这些刷题网站!...
mycat实现mysql数据库读写分离_Mycat实现MySQL读写分离
强制20天加班开发app后被集体解雇,象寻技术负责人公众号发文怒斥前领导
【Pytorch】基于GRU和LSTM的时间序列数据预测实现
论文解读(Graphormer)《Do Transformers Really Perform Bad for Graph Representation?》