I’m trying to write a function that does the arithmetic given a DNA sequence and a certain STR to count how many times the STR repeats in the DNA sequence and I started writing it but my function keeps returning 1, can you help me figure out why? Also, how can I pass the contents of a txt file as an argument for a function? So I don’t have to copy all the DNA sequence into the argument.
from cs50 import get_string from sys import argv def str_counter(DNA,STR): total = 0 i = 0 j = 4 for STR in DNA: if STR == DNA[i:j]: total += 1 else: i += 1 j += 1 return total print(str_counter("GGGGAATATGGTTATTAAGTTAAAGAGAAAGAAAGATGTGGGTGATATTAATGAATGAATGAATGAATGAATGAATGAATGTTATGATAGAAGGATAAAAATTAAATAAAATTTTAGTTAATAGAAAAAGAATATATAGAGATCAGATCTATCTATCTATCTTAAGGAGAGGAAGAGATAAAAAAATATAATTAAGGAA","AATG"))
Source: Python Questions