0

你能告诉我这段代码有什么问题吗?

def insert_sequence(str1, str2, index):
    '''The first two parameters are DNA sequences and the third parameter
       is an index. Return the DNA sequence obtained by inserting the second
       DNA sequence into the first DNA sequence at the given index.

       >>>insert_sequence('CCGG', 'AT',2)
       CCATGG

    '''
   str1 = str1[0:index] + str2 + str1[index:len(str1)]
   return str1
4

2 回答 2

5

您的文档字符串比函数体的其余部分缩进一个空格。要么将文档字符串缩进一个空格,要么将其余的缩进一个空格(可能是后者,因为如果我数正确的话,这将使它变成四个空格)。

于 2013-09-15T20:44:29.897 回答
0

Python 对缩进非常严格,因此您需要确保所有块都正确对齐,因此这里的问题是字符串比下面两行多一个空格。让它们对齐,你应该很好。

于 2013-09-15T20:47:08.287 回答