#RSC009. 选择题9
选择题9
- 下面 Python 代码执行后的输出是()
lstA=[2,-3,4,3,5,6,7,8,-2]
lstA.sort(key=abs,reverse=True)
print(lstA)
{{ select(121) }}
- [8,7,6,5,4,-3,3,-2,2]
- [8,7,6,5,4,-3,3,2,-2]
- [2,-2,-3,3,4,5,6,7,8]
- [-2,2,-3,3,4,5,6,7,8]
- 下面 Python 代码执行后的输出是()
setA=set("Python")
setB=set("python")
print(setA - setB)
{{ select(122) }}
- 'P'
- 'p'
- {'P'}
- {'p'}
- 某机构职工编码规则是“入职年份顺序码”,输入大写字母 Q 时结束输入,输出每个年份入职人数,横线处应填入的代码是()
statData={} # 保存每个年份对应的人数
while True:
ID=input("请输入职工编号:")
if ID=="Q":
break
Year=ID[:2] # 得到入职年份
# 填入代码
print(statData)
{{ select(123) }}
- statData[Year]+=statData.get(Year)+1
- statData[Year]=statData.get(Year,0)+1
- statData[Year]=statData.get(Year,None)+1
- statData[Year]+=1
- Python 表达式
[x for x in range(2,20) if x%3 and x%5==0]的值是() {{ select(124) }}
- [15]
- [5,10]
- [2,4,7,8,11,13,14,16,17,19]
- [3,6,9,12,18]
- Python 代码实现十进制到 M 进制(M ≤16)的转换,横线处应填入代码()
N=int(input("请输入正整数:"))
M=int(input("请输入转换进制,不能大于16:"))
Alpha="0123456789ABCDEF"
rst="" # 保存转换结果
while N!=0:
Remainder=N%M # 余数
N=N//M
# 填入代码
print(rst)
{{ select(125) }}
- rst+=Alpha[Remainder]
- rst=Alpha[Remainder]+rst
- rst=rst+Alpha[Remainder]
- rst=str(Remainder)+rst
- 下面 Python 代码实现字符串乱序(随机打乱),横线处应填入代码()
import random
a="123ABCxyz"
a=list(a)
a.sort(
print("".join(a))
{{ select(126) }}
- key=random.random
- key=lambda x:random.random(x)
- key=lambda x:random.random()
- key=lambda x:random.random
- 二进制数
101101在十进制下是() {{ select(127) }}
- 50
- 45
- 55
- 43
- Python 内置函数
len()对哪种类型无效?() {{ select(128) }}
- set
- tuple
- str
- file
- Python 表达式
len(set("12,34,56"))的值为() {{ select(129) }}
- 3
- 6
- 7
- 9
- 执行 Python 代码
print("李白".replace("白","杜"))后输出() {{ select(130) }}
- "李杜"
- "李白杜"
- "白杜"
- "李白"
- 执行 Python 代码
print(list(filter(lambda n:n%5,range(10))))后输出() {{ select(131) }}
- [0,5]
- [5,10]
- [1,2]
- [1,2,3,4,6,7,8,9]
- 执行 Python 代码
print([i for i in range(10) if i%5==0])后输出() {{ select(132) }}
- [0,5]
- [5,10]
- [0,1,2,3,4]
- [0,5,10]
- 下面 Python 代码执行时输入
10,20后输出()
a,b=input().split(",")
print(a+b)
{{ select(133) }}
- 30
- 1020
- 10,20
- 102
- 在 Python 中执行以下代码,输出结果是 None
a=(5,6,3,10)
print(a.sort())
{{ select(134) }}
- None
- (3,5,6,10)
- (5,6,3,10)
- 程序报错
- 程序运行结果是()
a='hello python'
print(a,end='_')
print(a,end="")
print(a)
{{ select(135) }}
- hello python_hello pythonhello python
- hello python_hello pythonhello python
- hello python_hello python hello python
- hello python_hellopythonhellopython
- 小明运行程序结果是()
h=[6,15,1,0,7,9,5]
p=sorted(h)
print(p)
{{ select(136) }}
- (0,1,5,6,7,9,15)
- (15,9,7,6,5,1,0)
- [0,1,5,6,7,9,15]
- [15,9,7,6,5,1,0]
- 运行如下代码,若输入整数 3,则最终输出()
def f(x):
if x==1:
s=1
else:
s=f(x-1)*x
return s
n=int(input("请输入一个大于1的整数:"))
print(f(n)+f(n-1))
{{ select(137) }}
- 2
- 4
- 8
- 16
- 运行程序输出()
def fun(x):
if x>3:
return x*fun(x-1)
else:
return x
print(fun(6))
{{ select(138) }}
- 120
- 360
- 720
- 60
- 下列关于递归的描述不正确的是() {{ select(139) }}
- 递归函数一定包含 if 语句
- 递归函数体内一定包含调用自身的语句
- 调用自身函数时需要明确的边界条件与边界值
- 递归算法一般代码简洁,执行效率高,空间复杂度低
- 运行程序输出()
def fun(a,n):
s=0
for i in range(1,n+1):
temp=str(a)*i
s+=int(temp)
return s
print(fun(1,3))
{{ select(140) }}
- 3
- 6
- 12
- 123