Given the following python code: def one_dna_to_rna(c): \"\"\"function takes a s
ID: 3873499 • Letter: G
Question
Given the following python code:
def one_dna_to_rna(c):
"""function takes a single-character string c representing a DNA nucleotide
and returns the corresponding messenger-RNA nucleotide."""
assert(len(c) == 1)
if c == 'A':
return 'U'
if c == 'C':
return 'G'
if c == 'G':
return 'C'
if c == 'T':
return 'A'
elif c not in 'ACGT':
return ' '
write a function called transcribe(s) that takes as input a string s representing a piece of DNA, and that uses recursion to construct and return a string representing the corresponding RNA. Any characters in the input that don’t correspond to a DNA nucleotide should not appear in the returned RNA string.
Explanation / Answer
Python 2.7 code:
def one_dna_to_rna(c):
"""function takes a single-character string c representing a DNA nucleotide
and returns the corresponding messenger-RNA nucleotide."""
assert(len(c) == 1)
if c == 'A':
return 'U'
if c == 'C':
return 'G'
if c == 'G':
return 'C'
if c == 'T':
return 'A'
elif c not in 'ACGT':
return ' '
def transcribe(s):
RNA = ""
for c in s:
if(one_dna_to_rna(c) == ' '):
pass
else:
RNA = RNA + one_dna_to_rna(c)
return RNA
print transcribe("ACTG")
Sample Output:
UGAC
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.