This question is in reference to lesson: https://www.codecademy.com/courses/learn-python/projects/dna
Specifically step #13. We write a function (below) that counts codons. The function of the if statement is to determine if i + 3 ie:the length of a next codon exceeds the length of the total dna string.
#code directly from the hint
for i in range(0, len(dna), 3):
if (i + 3) < len(dna):
If i shortened the file down to 3 codons or 9 letters, the last codon was always missed. IE: A list of 9 characters always showed 2 codons.
What I found is that this needed to be modified to “if (i + 3) <= len(dna):” to operate properly. Once I did that I got 3 codons for strings of 9, 10, or 11 chars and 4 codons for 12 chars.
Did anybody else do this same testing? Can you tell me what I may have missed?