全国计算机二级Python-第11套-基本操作-43

考生文件夹下存在一个文件PY103.py,请写代码替换横线,不修改其他代码,实现以下功能:
在一组单词中,查找出所有长度最长的单词,如果给定的一组单词
是: “cad”, “VB”,”Python”,”MATLAB” “hello”, “world”则输出结果为:
the longest words are:
Python
MATLAB

 

参考答案


def proc(strings):

m = 0

lst = []

for i in range(len(strings)):

if len(strings[i]) > m:

m = len(strings[i])

for i in range(len(strings)):

if len(strings[i]) == m:

lst.append(strings[i])

return lst

 

strings = ['cad' ,'VB', 'Python', 'MATLAB', 'hello', 'world']

result = proc(strings)

print("the longest words are:")

for item in result:

print("{: >25}".format(item))

历年真题

全国计算机二级Python-第11套-基本操作-42

2024-4-19 14:53:27

历年真题

全国计算机二级Python第11套-简单应用-44

2024-4-22 8:59:32

个人中心
购物车
优惠劵
今日签到
搜索