120k views
25 votes
Create your own Python file in a code editor of choice and begin writing functions as defined below. Your function names, inputs, and outputs should be exactly as described. Please make sure you follow the coding guidelines from the main rubric! def dna_count(dna): This function takes in a string representing a DNA sequence and returns a list or tuple of four integers representing the number of times each nucleotide A, C, G, or T occur in the DNA string, in that order.

User Mudassar
by
5.1k points

1 Answer

5 votes

Answer:

In python:

def dna_count(dna):

A = dna.count('A'); C = dna.count('C')

G = dna.count('G'); T = dna.count('T')

dna_countlist = []

dna_countlist.append(A) dna_countlist.append(C)

dna_countlist.append(G) dna_countlist.append(T)

return dna_countlist

dna = input("DNA: ")

print(dna_count(dna))

Step-by-step explanation:

This defines the function

def dna_count(dna):

This counts the occurrence of A and C

A = dna.count('A'); C = dna.count('C')

This counts the occurrence of G and T

G = dna.count('G'); T = dna.count('T')

This creates an empty list

dna_countlist = []

This appends the occurrence of A and C to the empty list

dna_countlist.append(A) dna_countlist.append(C)

This appends the occurrence of G and T to the list

dna_countlist.append(G) dna_countlist.append(T)

This returns the list

return dna_countlist

The main begins here

This prompts the user for the DNA string

dna = input("DNA: ")

This calls the dna_count function and also prints the returned list

print(dna_count(dna))

User Klanto Aguntuk
by
4.6k points