DNA.py no suspect


#1



DNA.py works but all suspects are freed.

I think there should be at least one suspect. Maybe my code frees everyone.


Find a suspect


Replace this line with your code. 
sample = ['GTA','GGG','CAC']

def read_dna(dna_file):
  dna_data = ""
  with open(dna_file, "r") as f:
    for line in f:
      dna_data += line
  return dna_data
def dna_codons(dna):
  codons = []
  for i in range(0, len(dna), 3):
    if (i + 3) < len(dna):
      codons.append(dna[i:i+3])
    return codons
def match_dna(dna):
  matches = 0
  for codon in dna:
    if codon in sample:
      matches += 1
  return matches
def is_criminal(dna_sample):
  dna_data = read_dna(dna_sample)
  codons = dna_codons(dna_data)
  num_matches = match_dna(codons)
  if num_matches >= 3:
    print "# of codon matches: %s. DNA profile matches. Continue investigation." % num_matches
  else:
    print "Not enough codon matches. Free suspect"
is_criminal("suspect1.txt")
is_criminal("suspect2.txt")
is_criminal("suspect3.txt")


#2

Hi, @lestroy14 ,

Your code is a more lenient judge than mine, which did identify a suspect.

Some leaked information suggests that the spy has hacked Codecademy's server and meddled with users' Python code in order to escape detection. :wink: In order to repair any damage that the spy may have done to your code, check, closely, the indentation of your return statements to make sure than none of them have been made part of a for loop. If one of them has become part of a for loop, it can cause a function to return during the first iteration of the loop, before all the crucial evidence has been examined. This might mean that a spy has been set free. :open_mouth:

P.S. (July 20, 2016): Let us know when you do identify a suspect, but be sure not to reveal who it is. That's classified information, there for other users to discover.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.