#HackTheVirus: Counting nucleotides

In this second task, you are asked to count DNA nucleotides in a given sequence. A DNA sequence can be understood as a string, an ordered collection of symbols from the DNA alphabet: ‘A’, ‘C’, ‘G’ and ‘T’. Each of these symbols represents a DNA nucleotide: adenine (‘A’), cytosine (‘C’), guanine (‘G’), and thymine (‘T’).

Given a string representing a DNA sequence, you have to write a function that counts how many nucleotides of each type compose the sequence; that is, how many symbols ‘A’, ‘C’, ‘G’ and ‘T’ there are (and in this order!). For example:

seq1 = ‘ATATTAGGTTTTTACCTACCCAGGAAAAGCCAACCAACCTCGATCTCTTGTAGATCTGTTCTCTAAACGA’

count_nucleotides(seq1)Output: [21, 18, 10, 21]

The input here is the DNA sequence stored as a string in variable seq1. The output is a list indicating that there are 21 ‘A’, 18 ‘C’, 10 ‘G’ and 21 ‘T’ in the sequence.

Ready? Implement your function below:

Got it? Check your code to get the password:

To check if your code solves correctly the problem, follow these steps in the interactive console:

  1. Copy your code above for the definition of count_nucleotides(DNA_seq) function in the console (you may need to do this line by line). Important: Copy the whole function definition: def count_nucleotides(DNA_seq): …
  2. Call check.check(count_nucleotides) in the console and press ENTER.
  3. If your code gives the correct answer, you will retrieve the password to get to the next exercise!
Protected Area

This content is password-protected. Please verify with a password to unlock the content.