我是编程新手,无法让我的主要功能正常工作。我的print语句给出了错误:
候选人未定义
但我的findBestCandidate
功能不应该提供吗?我究竟做错了什么??任何让我朝着正确方向前进的帮助都会很棒!
def fileToList(filename):
import os.path
if os.path.isfile(filename) == True:
file = open(filename, "r")
strings = file.read().splitlines()
file.close()
return strings
if os.path.isfile(filename) == False:
return []
def returnFirstString(strings):
string = ''
if len(strings) != 0:
string = string + strings[0]
return string
def strandsAreNotEmpty(strand1,strand2):
if len(strand1) != 0 and len(strand2) != 0:
return True
return False
def strandsAreEqualLengths(strand1,strand2):
if len(strand1) == len(strand2):
return True
return False
def findLargestOverlap(target,candidate):
if len(target) != len(candidate):
return -1
if len(target) == 0 or len(candidate) == 0:
return -1
c = ''
ol = 0
for char in candidate:
c += char
if target[(len(target)-len(c)):] == c:
ol = len(c)
return ol
def findBestCandidate(target,candidates):
overlap = 0
candidate = ''
for can in candidates:
ol = findLargestOverlap(target, can)
if ol > overlap:
overlap = ol
candidate = can
return (candidate, overlap)
def joinTwoStrands(target,candidate,overlap):
return target+candidate[overlap:]
def main():
target = input('Enter target strand filename:')
candidates = input('Enter candidate strands filename:')
fileToList(target)
fileToList(candidates)
findBestCandidate(target,candidates)
print(joinTwoStrands(target,candidate,overlap))
if __name__ == '__main__':
main()
答案 0 :(得分:0)
对于你的findBestCandidate函数,你应该像这样调用它,以相同的方式继续进行其他函数调用,即将结果存储在main中的变量
def main():
...
candidate, overlap = findBestCandidate(target,candidates)
...