Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coding: utf-8
- sample = ['GTA', 'GGG', 'CAC']
- def readDNA(dna_file):
- dna_data = ""
- with open(dna_file, "r") as f:
- for line in f:
- dna_data += line
- return dna_data
- def dnaCodons(dna):
- codons = []
- for i in range(0, len(dna), 3):
- if (i+3) < len(dna):
- codons.append(dna[i:i+3])
- return codons
- def matchDNA(dna):
- matches = 0
- for codon in dna:
- if codon in sample:
- matches += 1
- return matches
- def isCriminal(dna_sample):
- dna_data = readDNA(dna_sample)
- codons = dnaCodons(dna_data)
- num_matches = matchDNA(codons)
- if num_matches >= 3:
- print "Matches total: %s" % (str(num_matches))
- print "The investigation should continue."
- else:
- print "Matches total: %s" % (str(num_matches))
- print "The suspect can be set free."
- isCriminal('suspect1.txt')
- isCriminal('suspect2.txt')
- isCriminal('suspect3.txt')
Add Comment
Please, Sign In to add comment