Question
write a function in python called count_starts that has the following signature (a function signature describes the input types and output type, with type annotations
write a function in python called count_starts that has the following signature (a function "signature" describes the input types and output type, with type annotations the def line suffices): count_starts(seq: str) -> int, which should take a DNA-string, and count the occurrences of "ATG" in it, and return the answer. Once you are satisfied it works well, add the following lines so that your program will crash if it can't handle these specific test cases:
assert count_starts("ATATGCGATGGACGATGC") == 3, "Error on test 1!"
assert count_starts("ATG") == 1, "Error on test 2!"
assert count_starts("ATGCATG") == 2, "Error on test 3!"
When I run your program, there shouldn't be any errors (in fact, not much output at all!).
Note 1: Your function should follow at least "Rule 1" of functions. In brief, the function block should not access any variables that are not *local* variables (ie, those that are parameters in the definition line, or those created by the function itself).
Note 2: Use a while-loop to solve this; if seq: str = "ATGCATG", consider that the first 3-letter string occurs at seq[0:3], the second at seq[1:4], and the last 3-letter string occurs at seq[4:7] (and notice that here len(seq) is 7). In general, if index is the start of a 3-letter "window" in the sequence, then seq[index:(index + 3)] accesses the window. However, index + 3 should never be longer than len(seq), otherwise you'll be trying to read off the end of the string (which frustratingly is not an error in Python: for this example seq[5:30] returns just "TG". But still, don't do that.)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started