def pre_fix(s1, s2):
len_s1 = len(s1)
s1_loop = ""
s2_loop = ""
common_word = 0
for i in range(0, len_s1):
s1_loop += s1[i]
s2_loop += s2[i]
if s1_loop == s2_loop:
print(f"This {s1_loop} is s1 {s1} and s2 {s2} common word.")
s1_text = "distance"
s2_text = "disinfection"
pre_fix(s1_text, s2_text)
我觉得我这样是不是可以算作对呢!!!
2024.9.4今天我成功了。
首先代码。
def pre_fix(s1, s2):
len_s1 = len(s1)
s1_loop = ""
s2_loop = ""
number_text = 0
common_word = 0
for i in range(0, len_s1):
s1_loop += s1[i]
s2_loop += s2[i]
if s1_loop == s2_loop:
common_word += number_text
if common_word > number_text:
print(f"This {s1_loop} is s1 {s1} and s2 {s2} common word.")
number_text += 1
s1_text = "distance"
s2_text = "disinfection"
pre_fix(s1_text, s2_text)
这个代码可以识别dis,满足这道题。但是多了就又费了
s1_text = “disatance”
s2_text = “disatinfection”
下次再解决吧。