第一题:
创建一个列表my_list,其中包含[1, 1 000]中的所有整数,
再使用 min() 和 max() 核实该列表确实是从 1 开始,到 1 000 结束的。
此外,再对这个列表调用函数 sum(),看看 Python 将这一千个数字相加得到的结果是多少。
最后,对这个列表的所有整数求取平均值,直接保留一位小数。
输入描述:

输出描述:
输出三个整数,一个小数,每个数字独占一行。

备注:
1
1000
500500
500.5
题解:

my_list=[]
for i in range(1,1001):my_list.append(i)
print(min(my_list))
print(max(my_list))
A=sum(my_list)
print(A)
average=A/1000
print("{:.1f}".format(average))

第二题:
通过给函数 range()指定第三个参数来创建一个列表my_list,其中包含 [0, 19] 中的所有偶数;再使用一个 for 循环将这些数字都打印出来(每个数字独占一行)。
题解:

my_list=[]
for i in range(0,19,2):my_list.append(i)
for j in my_list:print("{}".format(j))

第三题:
创建一个列表my_list,其中包括 [1, 50] 内全部能被5整除的数字;再使用一个 for 循环将这个列表中的数字都打印出来(每个数字独占一行)。
题解:

my_list=[]
for i in range(5,51,5):my_list.append(i)
for j in my_list:print("{}".format(j))

第四题:
在Python中, * 代表乘法运算, ** 代表次方运算。
请创建一个空列表my_list,使用for循环、range()函数和append()函数令列表my_list包含底数2的 [1, 10] 次方,再使用一个 for 循环将这些次方数都打印出来(每个数字独占一行)。
题解:

my_list=[]
for i in range(1,11):j=2**imy_list.append(j)
for m in my_list:print("{}".format(m))

第五题:
使用列表解析生成一个列表my_list,其中包含前 10 个整数(也即[1, 10])的立方。
再直接使用print()语句把刚刚创建的列表my_list整个打印出来(以列表形式,也即两边带方括号)。
题解

my_list=[]
for i in range(1,11):j=pow(i,3)my_list.append(j)
print(my_list)

第六题:
创建一个列表group_list,其中依次包含字符串 ‘Tom’, ‘Allen’, ‘Jane’, ‘William’, ‘Tony’ 表示这个小组成员的名字。现有三项任务需要他们去完成,根据不同任务的繁琐度和实际情况需要分别派2人、3人、2人来完成,他们决定通过对列表分片来分配任务。
使用print()语句和切片来打印列表group_list的前两个元素表示去做第一个任务的人的名字,
再使用print()语句和切片来打印列表group_list的中间三个元素表示去做第二个任务的人的名字,
再使用print()语句和切片来打印列表group_list的后两个元素表示去做第三个任务的人的名字。
输入描述:

输出描述:
按照题意输出
[‘Tom’, ‘Allen’]
[‘Allen’, ‘Jane’, ‘William’]
[‘William’, ‘Tony’]
题解

group_list=[ 'Tom', 'Allen', 'Jane', 'William', 'Tony']
print(group_list[0:2])
print(group_list[1:4])
print(group_list[3:])

第七题:
创建一个依次包含字符串’Niuniu’、‘Niumei’、‘HR’、‘Niu Ke Le’、‘GURR’ 和 ‘LOLO’ 的列表users_list,
使用for循环遍历users_list,如果遍历到的用户名是 ‘HR’ ,则使用print()语句一行打印字符串 ‘Hi, HR! Would you like to hire someone?’,否则使用print()语句一行打印类似字符串 ‘Hi, Niuniu! Welcome to Nowcoder!’ 的语句。
输入描述:

输出描述:
按题目描述进行输出即可。
Hi, Niuniu! Welcome to Nowcoder!
Hi, Niumei! Welcome to Nowcoder!
Hi, HR! Would you like to hire someone?
Hi, Niu Ke Le! Welcome to Nowcoder!
Hi, GURR! Welcome to Nowcoder!
Hi, LOLO! Welcome to Nowcoder!
题解:

users_list=['Niuniu','Niumei','HR','Niu Ke Le','GURR' ,'LOLO']
for i in users_list:if i=="HR":print("Hi, {}! Would you like to hire someone?".format(i))else:print("Hi, {}! Welcome to Nowcoder!".format(i))

第八题:
创建一个空列表my_list,如果列表为空,请使用print()语句一行输出字符串’my_list is empty!‘,
否则使用print()语句一行输出字符串’my_list is not empty!’。
题解:

my_list=[]
if len(my_list)==0:print("my_list is empty!")
else:print("my_list is not empty!")

第九题:
描述
创建一个依次包含字符串’Niuniu’、‘Niumei’、‘GURR’和’LOLO’的列表current_users,
再创建一个依次包含字符串’GurR’、‘Niu Ke Le’、'LoLo’和’Tuo Rui Chi’的列表new_users,
使用for循环遍历new_users,如果遍历到的新用户名在current_users中,
则使用print()语句一行输出类似字符串’The user name GurR has already been registered! Please change it and try again!'的语句,
否则使用print()语句一行输出类似字符串’Congratulations, the user name Niu Ke Le is available!'的语句。(注:用户名的比较不区分大小写)
输入描述:

输出描述:
按题目描述进行输出即可。
The user name GurR has already been registered! Please change it and try again!
Congratulations, the user name Niu Ke Le is available!
The user name LoLo has already been registered! Please change it and try again!
Congratulations, the user name Tuo Rui Chi is available!
题解

current_users=['Niuniu','Niumei','GURR','LOLO']
min=[]
new_users=['GurR','Niu Ke Le','LoLo','Tuo Rui Chi']
for j in current_users:min.append(j.lower())
for i in new_users:if i.lower() in min:print("The user name {} has already been registered! Please change it and try again!".format(i))else:print("Congratulations, the user name {} is available!".format(i))

第十题:
某食堂今天中午售卖 ‘pizza’:10块钱一份,‘rice’ :2块钱一份,‘yogurt’:5块钱一份,剩下的其他菜品都是8块钱一份。
请创建如下一个order_list记录点单情况:
[‘rice’, ‘beef’, ‘chips’, ‘pizza’, ‘pizza’, ‘yogurt’, ‘tomato’, ‘rice’, ‘beef’]
然后使用for循环遍历列表order_list,使用if-elif-else结构依次打印每份菜品及其价格,且每个菜品都独占一行,按照’beef is 8 dollars’的形式。
并且在遍历过程中将价格相加,求对于这些点单记录,食堂总共营业收入多少?(单独输出一个整数)
输入描述:

输出描述:
按题目描述进行输出即可。
rice is 2 dollars
beef is 8 dollars
chips is 8 dollars
pizza is 10 dollars
pizza is 10 dollars
yogurt is 5 dollars
tomato is 8 dollars
rice is 2 dollars
beef is 8 dollars
61
题解:
使用字典的方式进行匹配

price={ 'pizza':10,'rice':2,'yogurt':5, 'beef':8,'chips':8,'tomato':8}
order_list=['rice', 'beef', 'chips', 'pizza', 'pizza', 'yogurt', 'tomato', 'rice', 'beef']
money=0
for food in order_list:if food in price:m=price[food]money+=mprint("{} is {} dollars".format(food,m))
print(money)

第十一题:
又到了一年一度的牛客运动会,Tom和Andy报名参加了项目,
但由于比赛前一天,Andy喝了太多碳酸饮料,导致身体不适,所以临时让Allen上场了,
换人参赛需要修改参赛名单,请完成以下内容模拟整个过程。

请创建一个依次包含字符串’Tom’和’Andy’的元组my_tuple,
先使用print()语句一行打印字符串’Here is the original tuple:',再使用for循环将元组my_tuple的内容打印出来;

请使用try-except代码块执行语句my_tuple[1] = ‘Allen’,
若引发TypeError错误,先输出一个换行,再使用print()语句一行打印字符串"my_tuple[1] = ‘Allen’ cause cause a TypeError: ‘tuple’ object does not support item assignment";

再重新对my_tuple赋值一个新元组,新元组依次由字符串’Tom’和’Allen’构成。
输出一个换行,先使用print()语句一行打印字符串’The tuple was changed to:',再使用for循环将元组my_tuple的内容打印出来,确定修改无误。
输入描述:

输出描述:
按题目描述进行输出即可(注意前后两个输出部分需以一个空行进行分隔)。
Here is the original tuple:
Tom
Andy

my_tuple[1] = ‘Allen’ cause a TypeError: ‘tuple’ object does not support item assignment

my_tuple was changed to:
Tom
Allen
题解:

my_tuple=('Tom','Andy')
print("Here is the original tuple:")
for i in my_tuple:print(i)
try:my_tuple[1] = 'Allen'
except:print()print("my_tuple[1] = 'Allen' cause a TypeError: 'tuple' object does not support item assignment")my_tuple=('Tom','Allen')
print()
print('my_tuple was changed to:')
for j in my_tuple:print(j)

第十二题:
创建一个依次包含键-值对’<‘: ‘less than’和’==’: ‘equal’的字典operators_dict,
先使用print()语句一行打印字符串’Here is the original dict:’,
再使用for循环遍历 已使用sorted()函数按升序进行临时排序的包含字典operators_dict的所有键的列表,使用print()语句一行输出类似字符串’Operator < means less than.'的语句;

对字典operators_dict增加键-值对’>': ‘greater than’后,
输出一个换行,再使用print()语句一行打印字符串’The dict was changed to:’,
再次使用for循环遍历 已使用sorted()函数按升序进行临时排序的包含字典operators_dict的所有键的列表,使用print()语句一行输出类似字符串’Operator < means less than.'的语句,确认字典operators_dict确实新增了一对键-值对。
题解:

operators_dict={'<':'less than','==':'equal'}
print('Here is the original dict:')
for i,j in sorted(operators_dict.items()):print("Operator {} means {}.".format(i,j))
operators_dict['>']='greater than'
print()
print('The dict was changed to:')
for i,j in sorted(operators_dict.items()):print("Operator {} means {}.".format(i,j))

第十三题:
又到了毕业季,牛牛作为牛客大学的学生会主席,决定对本校的应届毕业生进行就业调查。
他创建了一个依次包含字符串’Niumei’、‘Niu Ke Le’、‘GURR’和’LOLO’的列表survey_list,作为调查名单;
又创建了一个依次包含键-值对’Niumei’: ‘Nowcoder’和’GURR’: 'HUAWEI’的字典result_dict,作为已记录的调查结果。
请遍历列表survey_list,如果遍历到的名字已出现在 包含字典result_dict的全部键的列表 里,
则使用print()语句一行输出类似字符串’Hi, Niumei! Thank you for participating in our graduation survey!'的语句以表达感谢,
否则使用print()语句一行输出类似字符串’Hi, Niu Ke Le! Could you take part in our graduation survey?'的语句以发出调查邀请。
输入描述:

输出描述:
按题目描述进行输出即可。
Hi, Niumei! Thank you for participating in our graduation survey!
Hi, Niu Ke Le! Could you take part in our graduation survey?
Hi, GURR! Thank you for participating in our graduation survey!
Hi, LOLO! Could you take part in our graduation survey?
题解:
这道题跟前面的食品题几乎一样

survey_list=['Niumei','Niu Ke Le','GURR','LOLO']
result_dict={'Niumei':'Nowcoder','GURR':'HUAWEI'}
for i in survey_list:if i in result_dict:#       m=result_dict[i]print('Hi, {}! Thank you for participating in our graduation survey!'.format(i))else:print('Hi, {}! Could you take part in our graduation survey?'.format(i))

第十四题:
创建一个依次包含键-值对{‘name’: ‘Niuniu’和’Student ID’: 1}的字典my_dict_1,
创建一个依次包含键-值对{‘name’: ‘Niumei’和’Student ID’: 2}的字典my_dict_2,
创建一个依次包含键-值对{‘name’: ‘Niu Ke Le’和’Student ID’: 3}的字典my_dict_3,
创建一个空列表dict_list,使用append()方法依次将字典my_dict_1、my_dict_2和my_dict_3添加到dict_list里,
使用for循环遍历dict_list,对于遍历到的字典,使用print()语句一行输出类似字符串"Niuniu’s student id is 1."的语句以打印对应字典中的内容。
输入描述:

输出描述:
按题目描述进行输出即可。
Niuniu’s student id is 1.
Niumei’s student id is 2.
Niu Ke Le’s student id is 3.
题解:

my_dict_1={'name': 'Niuniu','Student ID': 1}
my_dict_2={'name': 'Niumei','Student ID': 2}
my_dict_3={'name': 'Niu Ke Le','Student ID': 3}
dict_list=[]
dict_list.append(my_dict_1)
dict_list.append(my_dict_2)
dict_list.append(my_dict_3)
for i in dict_list:print("{}'s student id is {}.".format(i['name'],i['Student ID']))

第十五题:
瑞驰调查了班上部分同学喜欢哪些颜色,并创建了一个依次包含键-值对’Allen’: [‘red’, ‘blue’, ‘yellow’]、‘Tom’: [‘green’, ‘white’, ‘blue’]和’Andy’: [‘black’, ‘pink’]的字典result_dict,作为已记录的调查结果。
现在驼瑞驰想查看字典result_dict的内容,你能帮帮他吗?
使用for循环遍历"使用sorted()函数按升序进行临时排序的包含字典result_dict的所有键的列表",对于每一个遍历到的名字,先使用print()语句一行输出类似字符串"Allen’s favorite colors are:"的语句,然后再使用for循环遍历该名字在字典result_dict中对应的列表,依次输出该列表中的颜色。
输入描述:

输出描述:
按题目描述进行输出即可。
Allen’s favorite colors are:
red
blue
yellow
Andy’s favorite colors are:
black
pink
Tom’s favorite colors are:
green
white
blue
题解:

result_dict={'Allen': ['red', 'blue', 'yellow'],'Tom': ['green', 'white', 'blue'],'Andy': ['black', 'pink']}
for i in sorted(result_dict):print("{}'s favorite colors are:".format(i))for j in result_dict[i]:print(j)

第十六题:
创建一个依次包含键-值对’Beijing’: {Capital: ‘China’}、‘Moscow’: {Capital: ‘Russia’}和’Paris’: {Capital: ‘France’}的字典cities_dict,
请使用for循环遍历"已使用sorted()函数按升序进行临时排序的包含字典cities_dict的所有键的列表",
对于每一个遍历到的城市名,使用print()语句一行输出类似字符串’Beijing is the capital of China!'的语句。
输入描述:

输出描述:
按题目描述进行输出即可。
Beijing is the capital of China!
Moscow is the capital of Russia!
Paris is the capital of France!
题解:

cities_dict={'Beijing': {'Capital': 'China'},'Moscow': {'Capital': 'Russia'},'Paris': {'Capital': 'France'}}
for i in sorted(cities_dict):for key in cities_dict[i]:print("{} is the {} of {}!".format(i,key.lower(),cities_dict[i][key]))

第十七题:
请定义一个函数cal(),该函数返回两个参数相减的差。
输入第一个数字记录在变量x中,输入第二个数字记录在变量y中,将其转换成数字后调用函数计算cal(x, y),再交换位置计算cal(y, x)。
输入描述:
输入两个整数。
输出描述:
根据题目描述输出两个差,每个数字单独一行。
示例1
输入:
3
5
输出:
-2
2
题解:

def cal(b,c):a=0a=b-cprint(a)
x=eval(input())
y=eval(input())
cal(x,y)
cal(y,x)

第十八题:
假如牛牛一个列表 friends_list 记录了他最好的几个朋友:[‘Niu Ke Le’, ‘Niumei’, ‘Niuneng’, ‘GOLO’],现在他想将列表里的名字替换成从0开始的数字,依次表示这几个朋友的重要性。
请写一个replace函数,第一个参数是列表friends_list,第二个参数是要替换的数字index,即在函数中将列表元素修改成成列表下标值。
请使用print函数直接打印修改前的列表。
使用for循环遍历列表 friends_list,每次调用replace函数替换列表中相应下标的元素。
结束循环后,再次使用print函数直接打印修改后的列表,查看是否替换成功。
输入描述:

输出描述:
[‘Niu Ke Le’, ‘Niumei’, ‘Niuneng’, ‘GOLO’]
[0, 1, 2, 3]
题解:

friends_list=['Niu Ke Le', 'Niumei', 'Niuneng', 'GOLO']
print(friends_list)
def replace(list,index):list[index]=index
for i in range(0,len(friends_list)):replace(friends_list,i)
print(friends_list)

第十九题:
假如这是一台自动售卖饮料机的一段程序:
使用print()语句一行输出字符串 ‘What kind of drink would you like?’ ,
然后使用input()函数读取字符串,并将读取到的字符串存储到变量kind_of_drink中,
假设读取到饮料是可乐(cola),也即变量kind_of_drink的内容为’cola’,
请使用print()语句一行输出字符串 ‘Below is your cola. Please check it!’ 。
其他饮料已经售空了,因此如果是其他字符串,则输出一句类似 ‘The milk has been sold out!’ 的信息。

输入描述:

输出描述:
按题目描述进行输出即可。
示例1
输入:
cola
复制
输出:
What kind of drink would you like?
Below is your cola. Please check it!
复制
题解:

print("What kind of drink would you like?")
kind_of_drink=input()
if kind_of_drink=='cola':print('Below is your {}. Please check it!'.format(kind_of_drink))
else:print('The {} has been sold out!'.format(kind_of_drink))

第二十题:
编写一个 while 循环模拟餐厅服务员询问客人一共有多少人用餐,要求在 while 循环中使用条件测试来结束循环。
每次循环开始先使用print()语句一行输出字符串 “Welcome! How many people, please?\nEnter ‘quit’ to end the program.”,
如果读取到字符串等于’quit’,则退出 while 循环,
否则将字符串转成整数,如果整数不超过4,则使用print()语句一行输出字符串 ‘Your small table is reserved!’;
如果整数大于4不超过6,则使用print() 语句一行输出字符串 ‘Your middle table is reserved!’;
如果整数大于6不超过10,则使用print() 语句一行输出字符串 ‘Your large table is reserved!’;
如果整数超过10,则使用print()语句一行输出字符串 ‘Sorry, there is no free table that seats over ten persons.’;
然后本次循环结束,再次进入 while 循环中的条件测试。
输入描述:
保证每一行的输入只有数字或字符串’quit’,且保证数字合法,范围在[1, 20]。
输出描述:
按题目描述进行输出即可。
示例1
输入:
2
18
quit
复制
输出:
Welcome! How many people, please?
Enter ‘quit’ to end the program.
Your small table is reserved!
Welcome! How many people, please?
Enter ‘quit’ to end the program.
Sorry, there is no free table that seats over ten persons.
Welcome! How many people, please?
Enter ‘quit’ to end the program.
题解:

while True:i=eval(input())print("Welcome! How many people, please?\nEnter 'quit' to end the program.")if i==quit:breakif i<=4:print('Your small table is reserved!')elif 4<i<=6:print('Your middle table is reserved!')elif 6<i<=10:print('Your large table is reserved!')else:print('Sorry, there is no free table that seats over ten persons.')

第二十一题:
编写一个 while 循环判断输入的字符串对应的十进制数值是否是被8整除的数字,要求使用布尔变量 active 来控制循环结束的时机。
每次循环开始先使用print()语句一行输出字符串 “Please enter a positive integer!\nEnter ‘quit’ to end the program.” ,
如果读取到字符串等于’quit’,则把布尔变量 active 的值更改为False,
否则将字符串转成整数,如果能被8整除即是8的倍数,则使用print()语句一行输出类似字符串’80 is a multiple of 8.'的语句,
否则使用print()语句一行输出类似字符串’4 is not a multiple of 8.‘的语句,
然后本次循环结束,再次进入 while 循环中的条件测试。
输入描述:
保证每一行的输入只有数字或字符串’quit’,且保证数字合法,范围在[1, 100]。
输出描述:
按题目描述进行输出即可。
示例1
输入:
1
16
quit
复制
输出:
Please enter a positive integer!
Enter ‘quit’ to end the program.
1 is not a multiple of 8.
Please enter a positive integer!
Enter ‘quit’ to end the program.
16 is a multiple of 8.
Please enter a positive integer!
Enter ‘quit’ to end the program.
题解:

active=True
while active:number=eval(input())print("Please enter a positive integer!\nEnter 'quit' to end the program.")if number==quit:active=Falsebreakn=number%8if n==0:print("{} is a multiple of 8.".format(number))else:print("{} is not a multiple of 8.".format(number))

第二十二题:
某游乐园院按照游客身高段收取票价:不到 1.0米 的游客免费; 1.0~1.2 米的游客为 80 元;超过 1.2 米的游客为 150 元。
请编写一个死循环,每次循环开始先使用print()语句一行输出字符串"Please tell me your height!\nEnter ‘quit’ to end the program."。
如果读取到的字符串等于’quit’,则使用 break 语句退出循环;
否则将字符串转成浮点数,如果小于1.0米,则使用print()语句一行输出字符串’Your admission cost is 0 yuan.‘,
如果大于等于1.0米且小于等于1.2米,则使用print()语句一行输出字符串’Your admission cost is 80 yuan.’,
如果大于1.2米,则使用print()语句一行输出字符串’Your admission cost is 150 yuan.‘,
然后本次循环结束,再次进入 while 循环中的条件测试。
输入描述:
保证每一行的输入只有浮点数或字符串’quit’,且保证数字合法,范围在[0, 3]。
输出描述:
按题目描述进行输出即可。
示例1
输入:
0.5
1.2
quit
复制
输出:
Please tell me your height!
Enter ‘quit’ to end the program.
Your admission cost is 0 yuan.
Please tell me your height!
Enter ‘quit’ to end the program.
Your admission cost is 80 yuan.
Please tell me your height!
Enter ‘quit’ to end the program.
题解:

while True:print("Please tell me your height!\nEnter 'quit' to end the program.")high=eval(input())if high==quit:breakif high<1.0:print("Your admission cost is 0 yuan.")elif 1.0<=high<=1.2:print("Your admission cost is 80 yuan.")else:print("Your admission cost is 150 yuan.")

第二十三题:
描述
创建一个依次包含字符串’chichen’、’ bacon’和’durian’的列表 pizza_orders,再创建一个名为 finished_pizza 的空列表,
使用 while 循环判断列表 pizza_orders 里面是否还有元素,如果有则使用pop()方法删掉将列表 pizza_orders 的最后一个元素,并把刚刚删掉的元素存到一个名为pizza的变量,假设pizza的值为’bacon’,请使用print()语句一行打印类似字符串’I made your bacon pizza!'的语句,并使用append()语句将pizza添加到列表 finished_pizza 的末尾,然后本次循环结束,再次进入 while 循环中的条件测试。
在 while 循环结束后,再使用print()语句把列表 finished_pizza 整个打印出来。

输入描述:

输出描述:
按题目描述进行输出即可。
I made your durian pizza!
I made your bacon pizza!
I made your chichen pizza!
[‘durian’, ‘bacon’, ‘chichen’]
题解:

pizza_orders=['chichen','bacon','durian']
finished_pizza=[]
while len(pizza_orders)!=0:pizza=pizza_orders.pop()print("I made your {} pizza!".format(pizza))finished_pizza.append(pizza)
print(finished_pizza)

第二十四题:
创建一个依次包含字符串’bacon’、‘durian’、‘bacon’、‘bacon’、‘chicken’和’durian’的列表pizza_inventory,
使用 while循环 判断字符串’bacon’是否存在于列表pizza_inventory中,
如果存在,则使用remove()方法删掉列表pizza_inventory中的一个字符串’bacon’,并使用print()语句一行输出字符串’A bacon pizza was deleted from list.‘,
然后本次循环结束,再次进入 while 循环中的条件测试。
在 while 循环结束后,如果if语句判断字符串’bacon’确实不在列表pizza_inventory中,请使用print()语句一行输出字符串’There is really no bacon in pizza_inventory!’。
输入描述:

输出描述:
按题目描述进行输出即可。
题解:
这道题题目出错了,不过影响不大

pizza_inventory=['bacon','durian','bacon','bacon','chicken','durian']
while 'bacon' in pizza_inventory:pizza_inventory.remove('bacon')print("A pastrami order was deleted from list.")
if 'bacon' not in pizza_inventory:print("There is really no pastrami in sandwich_orders!")

第二十五题:
创建一个名为survey_dict的空字典,
请编写一个死循环,
每次循环开始先使用print()语句一行输出字符串’If you have the chance, which university do you want to go to most?‘,
再使用print()语句一行输出字符串’What is your name?’,再将读取到的字符串存储在变量name中,
再使用print()语句一行输出字符串’Which university do you want to go to most?‘,再将读取到的字符串存储在变量university中,
再把键-值对name: university存储在字典survey_dict中,
再使用print()语句一行输出字符串"Is there anyone who hasn’t been investigated yet?",
如果输入的字符串为’No’,则使用 break 语句退出循环,否则本次循环结束,再次进入 while 循环中的条件测试。
在 while 循环结束后,使用for循环遍历 已使用sorted()函数按升序进行临时排序的包含字典survey_dict的所有键的列表,
对于每一个遍历到的被调查者的名字,使用print()语句一行输出类似字符串"I’am Tom. I’d like to go to Fudan University if I have the chance!"的语句。
输入描述:

输出描述:
按题目描述进行输出即可。
示例1
输入:
Tom
Fudan University
Yes
Ben
Peking University
Yes
Andy
Tsinghua University
No
复制
输出:
If you have the chance, which university do you want to go to most?
What is your name?
Which university do you want to go to most?
Is there anyone who hasn’t been investigated yet?
If you have the chance, which university do you want to go to most?
What is your name?
Which university do you want to go to most?
Is there anyone who hasn’t been investigated yet?
If you have the chance, which university do you want to go to most?
What is your name?
Which university do you want to go to most?
Is there anyone who hasn’t been investigated yet?
I’am Andy. I’d like to go to Tsinghua University if I have the chance!
I’am Ben. I’d like to go to Peking University if I have the chance!
I’am Tom. I’d like to go to Fudan University if I have the chance!
题解:

survey_dict={}
while True:print("If you have the chance, which university do you want to go to most?")print("What is your name?")name=input()print("Which university do you want to go to most?")university=input()survey_dict[name]=universityprint("Is there anyone who hasn't been investigated yet?")n=input()if n=='No':break
for i in sorted(survey_dict):print("I'am {}. I'd like to go to {} if I have the chance!".format(i,survey_dict[i]))

第二十六题:
描述
牛牛有一份字符串my_str = ‘I am$ Niuniuiuniuiuniu, an$d I amstuam stuamstudying in NowNowNowcoder!’ 被污染了,其中出现了很多奇怪的符号。现请你使用split函数将这份字符串从符号符号。 现请你使用split函数将这份字符串从符号符号。现请你使用split函数将这份字符串从符号处分割成众多字符列表,记录在my_list中,并使用print函数直接打印my_list中的结果。
然后再使用join函数将my_list中的分段字符串重新连接成一个新的字符串,并使用print函数输出。
输入描述:

输出描述:
[‘I am’, ’ N’, ‘iuniu’, ‘, an’, 'd I ', ‘am stu’, 'dying in ', ‘Now’, ‘coder!’]
I am Niuniu, and I am studying in Nowcoder!
题解:

my_str = 'I am$ N$iuniu$, an$d I $am stu$dying in $Now$coder!'
my_str=my_str.split('$')
print(my_str)
print(''.join(my_str))

Python入门到实践(上)(牛客网题库)day2相关推荐

  1. 牛客网题库公司真题 2021阅文C++方向笔试卷答案

    牛客网题库公司真题技术(软件)信息技术类 C++工程师 2021阅文C++方向笔试卷 以上的标题就是牛客网这个试卷的位置,链接在这里不确定以后是不是有效,我自己做个记录的:2021阅文C++方向笔试卷 ...

  2. 牛客网题库分享--final byte

    代码片段: byte b1=1,b2=2,b3,b6; final byte b4=4,b5=6; b6=b4+b5; b3=(b1+b2); System.out.println(b3+b6); 关 ...

  3. python刷题 NOI题库 python题解 洛谷、牛客网、AcWing 刷题等

    NOI题库 python题解-2022.01.07整理(1.1-1.3) NOI题库 python题解-2022.01.07整理(1.1-1.3)_dllglvzhenfeng的博客-CSDN博客 N ...

  4. 使用Python网络爬虫抓取牛客网题目

    文章目录 1. 背景 2. 前期准备 3. 获取网页内容 4. 内容处理 4.1. Limit 4.2. Problem Description 4.3. Input 4.4. Output 4.5. ...

  5. 20201212大一集训牛客网题之d题中学数学题

    链接:https://ac.nowcoder.com/acm/contest/9692/D 来源:牛客网 题目描述 这是一道很简单的中学数学题: 给定数n,求n!的p进制下有多少个后导零.非常简单. ...

  6. 牛客网题源(JavaScript)

    1.以下不属于JavaScript中的数据类型的选项是( C ) A.Undefined B.Number C.Interface D.Symbol == 基本类型有:String Number Bo ...

  7. sql牛客网题(摘选)

    sql题摘选 01 | join 1.inner join(关联四张表) 01 | join 1.inner join(关联四张表) 有一个,部门关系表dept_emp简况如下: 有一个部门经理表de ...

  8. Python程序设计题解【蓝桥杯官网题库】 DAY2-IDLE与基础练习

    更改IDLE字体大小方法 直接点击菜单栏的[Options] 第一道例题,嗯嗯系统测试很快,python用起来很生,很不舒服. 一直没用python写过代码题,尝试了一下,需要很长一段时间来接受了(呜 ...

  9. Python程序设计题解【蓝桥杯官网题库】 DAY15-算法训练

    试题 算法训练 最大的算式 资源限制 时间限制:1.0s 内存限制:256.0MB 问题描述 题目很简单,给出N个数字,不改变它们的相对位置,在中间加入K个乘号和N-K-1个加号,(括号随便加)使最终 ...

最新文章

  1. pythonrgbd图片像素对齐_利用pyrealsense获取深度图,并进行像素对齐
  2. 【深度学习】查准率、召回率、AP、mAP
  3. 最佳的七十五个网络分析和安全工具
  4. Tomcat中组件的生命周期管理(三)
  5. css不常用重要属性
  6. linux高亮查找关键字
  7. IntellijIDEA配置Maven
  8. c语言dummy作为参数,C语言中的dummy函数
  9. C语言C++编程软件推荐及下载方式
  10. Jenkins整合Sonar
  11. 数据库系统概述--数据库习题
  12. 云计算机房架构图,云计算架构技术与实践
  13. java助理工程师主要做什么工作,Java助理工程师面试的惨痛教训
  14. 华为云notebook在线解压压缩包问题
  15. EXCEL——提取身份证中的出生年月日
  16. 《假如爱有天意》月光如春风拂面,你如种子深埋我心
  17. 【特大消息】博客换地址啦!
  18. zookeeper安装配置的时候zoo.cfg配置信息分成了两个文件zoo.cfg.dynamic
  19. qt5 设置应用程序编码_2020年5大最佳编码应用
  20. win10 pip安装mmcv-full

热门文章

  1. 天使与海豚的爱情故事
  2. C语言 神奇的式子:n=n(n-1) 涵义,作用及其应用场景
  3. 《Android入门之旅》
  4. 新一轮芯片战的序幕?台积电狂砸两千亿突破2nm
  5. excel表的下载模板
  6. java获取枚举索引_Java枚举使用详解
  7. 「 每日一练,快乐水题 」728. 自除数
  8. R语言-基于豆瓣电影详情数据的清洗和多元回归分析
  9. 第98讲:使用SBT开发时动手解决rt.jar中CharSequence is broken等问题学习笔记
  10. 【翻译】用 安全即代码 保护你的GitOps流程