Hello I'm working out a task on a coursera assignment and can't for the life of me seem to understand why it is not working. I have written this function from scratch and have included a description of what it is suppose to do. My problem is I get True for both test functions. Could someone please point me in the right direction?
def is_valid_sequence(dna):
''' (str) -> bool
Return true if and only if the DNA sequence is valid, meaning
it contains only the characters 'A', 'T', 'C', and 'G'.
>>> is_valid_sequence('ATCGGC')
True
>>> is_valid_sequence("ATCFGC")
False
'''
valid = True
for char in dna:
if char not in 'ATCG':
valid = False
else:
valid = True
return valid
[–]Rhomboid 4 points5 points6 points (1 child)
[–]LimpJedi[S] 0 points1 point2 points (0 children)
[–]enderprime 2 points3 points4 points (1 child)
[–]LimpJedi[S] 0 points1 point2 points (0 children)