
例如,数字字符串“718”的编码为“BDABCA”。
用Python程序实现上述编码,功能如下:输入待编码的一串数字字符,输出编码结果,程序运行界面如下图所示。
请输入数字字符串:718 编码结果为:BDABCA |
(1)运行该程序,若输入的数字字符串为“8462”,则输出的编码结果为
(2)请在程序划线处填入合适的代码。
def dtob(x):
st,r="",0
for i in range(4):
①
st=str(r)+st
x=x//2
return st
code={"00":"A","01":"B","10":"C","11":"D"}
s=input("请输入数字字符串:")
result=""
for i in range(len(s)):
②
if"0"<=ch<="9":
ans=③
result+=code[ans[0:2]]+ ④
if result!="":
print("编码结果为:",result)
else:
print("输入错误!")

同类型试题

y = sin x, x∈R, y∈[–1,1],周期为2π,函数图像以 x = (π/2) + kπ 为对称轴
y = arcsin x, x∈[–1,1], y∈[–π/2,π/2]
sin x = 0 ←→ arcsin x = 0
sin x = 1/2 ←→ arcsin x = π/6
sin x = √2/2 ←→ arcsin x = π/4
sin x = 1 ←→ arcsin x = π/2


y = sin x, x∈R, y∈[–1,1],周期为2π,函数图像以 x = (π/2) + kπ 为对称轴
y = arcsin x, x∈[–1,1], y∈[–π/2,π/2]
sin x = 0 ←→ arcsin x = 0
sin x = 1/2 ←→ arcsin x = π/6
sin x = √2/2 ←→ arcsin x = π/4
sin x = 1 ←→ arcsin x = π/2

