I need to write a function which returns True if and only if the DNA sequence contains no characters other than 'A', 'T', 'C' and 'G')
Here is my code that produces this type of error - 'str' object does not support item assignment
def is_valid_sequence(dna):
i = 0
for dna[i] in dna:
if dna[i] in 'ATCG':
i = i +1
return True
else:
return False
I created another code for the same purpose but it checks only the first character in the sequence and I have no Idea how to make the loop check the following characters as well
def is_valid_sequence(dna):
i = 0
for char in dna:
if char in 'ATCG':
i = i +1
return True
else:
return False
Aucun commentaire:
Enregistrer un commentaire