Trouble tying everything together with main function using python -
i new programing , having trouble getting main function work. print statement gives me error:
candidate not defined
but shouldn't findbestcandidate
function provide it? doing wrong?? me in right direction awesome!
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 , 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 char in candidate: c += char if target[(len(target)-len(c)):] == c: ol = len(c) return ol def findbestcandidate(target,candidates): overlap = 0 candidate = '' 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()
for findbestcandidate function, should call this, proceed on same fashion other function calls, i.e. storing result in variables in main
def main(): ... candidate, overlap = findbestcandidate(target,candidates) ...
Comments
Post a Comment