def transcribe( s ):
""" output: messenger RNA produced by string s
input: a string s
"""
if len(s)==0:
return ''
else:
return one_dna_to_rna( s[0] ) + transcribe (s[1:])
def one_dna_to_rna( c ):
""" converts a single-character c from DNA
nucleotide to complementary RNA nucleotide
"""
if c == 'A':
return 'U'
elif c == 'T':
return 'A'
elif c == 'C':
return 'G'
elif c == 'G':
return 'C'
else:
return ''
答案 0 :(得分:1)
您的代码可以简化为以下三行:
dna2rna = { 'A':'U', 'T':'A', 'C':'G', 'G':'C' }
def transcribe2( s ):
return ''.join(dna2rna[c] for c in s)
示例:
>>> transcribe2('ACT')
'UGA'
检查报告的错误消息:
第13行def one_dna_to_rna(c):^ IndentationError:unindent与任何外部缩进级别不匹配
这意味着def one_dna_to_rna( c ):
的缩进有问题。
答案 1 :(得分:0)
与def one_dna_to_rna
相比,您似乎在def transcribe
之前有一个额外的空格。这很可能是缩进错误的原因。