該程式的目標是找到 B 中的起始位置,其中 A 作為錯誤最少的子串被找到。允許的最大錯誤數為 mxe。該函式應該回傳一對數字,(ai,ae),其中ai 是找到匹配的位置B,ae 是匹配中的錯誤數。
def sameletter(a,b):
if a==b:return True
def bestmatch(A,B,mxe):
bx = -1
errorsatbx = mxe 1
k = 0
while k<len(B)-len(A) and bx == -1:
ax = 0
i = 0
while i<len(A) and ax <= mxe:
if not(sameletter(A[i],B[i k])):
i =1
if ax <= mxe: bx = k
k = 1
return(bx, mxe)
bestmatch("ACTG","GTCACTGATC", 1)
程式運行但沒有回傳任何內容。
uj5u.com熱心網友回復:
我認為你應該試試這個:
def sameletter(a,b):
if a == b:
return True
def bestmatch(A,B,mxe):
bx = -1
errorsatbx = mxe 1
k = 0
while k < int(len(B) - len(A)) and bx == -1:
ax = 0
i = 0
while i < len(A) and ax <= mxe:
if not(sameletter(A[i],B[i k])):
i = 1
if ax <= mxe:
bx = k
k = 1
return(bx, mxe)
print (bestmatch("ACTG","GTCACTGATC", 1))
它至少回傳值,但我不知道這些值是您想要的還是正確的
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/375595.html
標籤:Python
上一篇:應用11月補丁后,從在Delphi11上崩潰的EXE檔案獲取版本資訊
下一篇:Python串列到字典中
