...
You have the reverse logic. You must check all positions. If any of them cannot identify itself as a nucleotide in "ACTG", then you immediately return False for the string. If you passed all the characters, can you confidently return True .
import string
def DnaCheck(squence_str):
for i in (squence_str):
if string.upper(i) not in "ACTG":
return False
return True
test_cases = ["", "AAJJ", "ACTG", "AACTGTCAA", "AACTGTCAX"]
for strand in test_cases:
print strand, DnaCheck(strand)
Conclusion:
True
AAJJ False
ACTG True
AACTGTCAA True
AACTGTCAX False
Prune source
share