-->
当前位置:首页 > 题库 > 正文内容

填空题:下面程序返回两个字符串从头开始的最长公共前缀。如distance和disinfection的最长公共前缀为dis

Luz3年前 (2022-05-26)题库973
下面程序返回两个字符串从头开始的最长公共前缀。如distance和disinfection的最长公共前缀为dis

def main():
s1 = input("Enter the first string: ").strip()
s2 = input("Enter the second string: ").strip()
s3 = prefix(s1, s2)
if s3 ___(1)___ None:
print("The common prefix is " + s3)
else:
print("No common prefix");

def prefix(s1, s2):
result = ""
for i in range(len(s1)):
if s1[i] == s2[i]:
result ___(2)___ s1[i]
else:
break;

if len(result) == 0:
return None
else:
return ___(3)___

main()

在下面9个答案中选择,空格中填编号,如A等

A)== B) != C) = D)+= E)+ F)%= G)1 H) 0 I)result

(1)的答案是
(2)的答案是
(3)的答案是







答案:
第1空:B ||

第2空:D ||

第3空:I ||

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。