*PYTHON Create a program that outputs the complementary DNA string¶ Deoxyribonuc
ID: 3751557 • Letter: #
Question
*PYTHON
Create a program that outputs the complementary DNA string¶
Deoxyribonucleic acid (DNA) is a chemical found in the nucleus of cells and carries the "instructions" for the development and functioning of living organisms. If you want to know more http://en.wikipedia.org/wiki/DNA
In DNA strings, symbols "A" and "T" are complements of each other, as are the "C" and "G" symbols. Your program will be given the input of a string which as a sequence of characters represents one side of the DNA; you need to get the other complementary side. For instance, if input is “ACGT” your output should be “TGCA”
The following pseudocode describes one algorithm for this program (there are other ways, too).
Create a variable DNA that stores a string of DNA symbols Create a variable DNA_COMPLEMENT to store the complement of the DNA. Initialize it to a blank string.
FOR EACH letter IN DNA
CHANGE A->T, T->A, C->G, G->C and add it to the DNA_COMPLEMENT string
PRINT DNA_COMPLEMENT string
Explanation / Answer
Answer
dnacomplement.py
#Get the input DNA sequence from the user in variable dna
dna = input('Enter the DNA sequence: ')
#create dna_complement to store the complement and intialize it to blank
dna_complement = ''
#function to get complement of each DNA symbol
def get_complement(nucleotide):
""" (str) -> str
returns the nucleotide's complement
>>>get_complement('A')
T
>>>get_complement('T')
A
>>>get_complement('C')
G
>>>get_complement('G')
C
"""
if nucleotide in 'ATCG':
if(nucleotide == 'A'):
return 'T'
if(nucleotide == 'T'):
return 'A'
if(nucleotide == 'C'):
return 'G'
if(nucleotide == 'G'):
return 'C'
#complement each char in the dna string using for loop over the string.
for char in dna:
dna_complement += get_complement(char)
#print the dna_complement in the shell window
print(dna_complement)
Output
Enter the DNA sequence: ACTG
TGAC
>>>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.