描述: 牛牛给了牛妹一个一串无规则的数字,牛妹将其转换成列表后,使用max和min函数快速的找到了这些数字的最值,你能用Python代码实现一下吗?
输入描述:输入一行多个整数,数字之间以空格间隔。
输出描述:输出这些数字的zui zhi
实现代码:
a = list(map(int,input().split()))
print(max(a))
print(min(a))
运行结果:
描述:牛牛想知道自己小组内的同事们的年龄和都有多少,他输入一串年龄序列,请将其转换成列表,并使用sum函数直接获取列表的和。
输入描述:一行输入多个正整数,以空格间隔。
输出描述:输出求和。
实现代码:
pizz_inventory = ['bacon', 'durian', 'bacon', 'bacon', 'chicken', 'durian']
while 'bacon' in pizz_inventory:
pizz_inventory.remove('bacon')
print('A pastrami order was deleted from list.')
if 'bacon' not in pizz_inventory:
print('There is really no pastrami in sandwich_orders!')
运行结果:
描述:
创建一个依次包含键-值对’<‘: ‘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 k,v in sorted(operators_dict.items()):
print(f'Operators {k} means {v}')
operators_dict['>']='greater than'
print()
print('The dict was changed to:')
for k,v in sorted(operators_dict.items()):
print(f'Operators {k} means {v}')
运行结果:
Here is the original dict:
Operators < means less than
Operators == means equal
The dict was changed to:
Operators < means less than
Operators == means equal
Operators > means greater than
描述:
又到了毕业季,牛牛作为牛客大学的学生会主席,决定对本校的应届毕业生进行就业调查。
他创建了一个依次包含字符串’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?‘的语句以发出调查邀请。
输入描述:保证每一行的输入只有浮点数或字符串’quit’,且保证数字合法,范围在[0, 3]。
输出描述:按题目描述进行输出即可。
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.keys():
print(f'Hi, {i}! Thank you for participating in our graduation survey!')
else:
print(f'Hi, {i}! 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?