Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote