Guest User

Untitled

a guest
Feb 23rd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. # coding: utf-8
  2. sample = ['GTA', 'GGG', 'CAC']
  3.  
  4. def readDNA(dna_file):
  5. dna_data = ""
  6. with open(dna_file, "r") as f:
  7. for line in f:
  8. dna_data += line
  9. return dna_data
  10.  
  11. def dnaCodons(dna):
  12. codons = []
  13. for i in range(0, len(dna), 3):
  14. if (i+3) < len(dna):
  15. codons.append(dna[i:i+3])
  16. return codons
  17.  
  18. def matchDNA(dna):
  19. matches = 0
  20. for codon in dna:
  21. if codon in sample:
  22. matches += 1
  23. return matches
  24.  
  25. def isCriminal(dna_sample):
  26. dna_data = readDNA(dna_sample)
  27. codons = dnaCodons(dna_data)
  28. num_matches = matchDNA(codons)
  29. if num_matches >= 3:
  30. print "Matches total: %s" % (str(num_matches))
  31. print "The investigation should continue."
  32. else:
  33. print "Matches total: %s" % (str(num_matches))
  34. print "The suspect can be set free."
  35.  
  36. isCriminal('suspect1.txt')
  37. isCriminal('suspect2.txt')
  38. isCriminal('suspect3.txt')
Add Comment
Please, Sign In to add comment