7. reverse


Hi all,
I can't understand the function.. Perhaps I may show you the problem of my assignment:

"Write a function ReverseComplement to solve the Reverse Complement Problem"

Find the reverse complement of a DNA string.
Input: A DNA string Pattern.
Output: The reverse complement of Pattern.

Sample Input:
Sample Output:

My code was:

Input: A DNA string Pattern

Pattern = "AAAACCCGGT"

Output: The reverse complement of Pattern

def ReverseComplement(Pattern):
    revComp = ''
    index = len(Pattern) - 1
    for i in range(0,len(Pattern)):
        revComp = revComp + Pattern[index]
        index = index - 1
        return revComp
print (ReverseComplement(Pattern))

Can Anyone explaining me why my output is "T"? What I can't see?

Thank you in advance


your for loop will run only once, since in the first run of the loop, a return keyword is reached. Place the return outside of the for loop, so the whole loop can run.

If you need further help, let me know