def get_orf(dna):
'''Function should take an argument (string) and find an ORF'''
stopVar = "TAA" or "TGA" or "TAG"
if argument[0:3] == "ATG":
return
else:
return ""
if stopVar in argument:
return argument[:argument.find(stopVar)]
else:
return argument
return
# Test Cases
#
# You may wish to add more test cases here
argument = 'ATGTGAA'
computed_result = get_orf( argument )
expected_result = 'ATG'
if ( computed_result == expected_result ):
print ("Test Case 1: Passed")
else:
print ("Test Case 1: Failed")
print ("Expected Result:", expected_result)
print ("Computed Result:", computed_result)
return
如果发现了
'ATG'
的情况,这是一个很好的做法,如果函数中的一个
return
返回某些内容,那么它们都应该即使是
None
:
def get_orf(dna):
"""Function should take an argument (string) and find an ORF."""
stopVar = "TAA" or "TGA" or "TAG"
if dna[0:3] == "ATG":
return "ATG"
elif stopVar in dna:
return dna[:dna.find(stopVar)]
else:
return dna
# Test Cases
#
# You may wish to add more test cases here
argument = 'ATGTGAA'
computed_result = get_orf(argument)
expected_result = 'ATG'
if (computed_result == expected_result):
print ("Test Case 1: Passed")
else:
print ("Test Case 1: Failed")
print ("Expected Result:", expected_result)
print ("Computed Result:", computed_result)
与argument = 'ATGTGAA'
:
Test Case 1: Passed
与argument = 'GATGTGAA'
:
Test Case 1: Failed
Expected Result: ATG
Computed Result: GATGTGAA
函数的 docstring
也带有
"""Text."""
而不是单引号,所以我改变了它。