#!/usr/bin/python


def findstem(strand1, strand2):
    tag = 1
    for j in range(0, 5):
        base1 = strand1[j]
        base2 = strand2[4 - j]
        if not pair(base1, base2):
            tag = 0
    if tag == 1:
        return 1


def pair(base1, base2):
    if    base1 == 'G' and base2 == 'C' \
       or base1 == 'G' and base2 == 'U' \
       or base1 == 'A' and base2 == 'U' \
       or base1 == 'C' and base2 == 'G' \
       or base1 == 'U' and base2 == 'A' \
       or base1 == 'U' and base2 == 'G':
        return 1


seq = 'GAGAGCAGUGGGGGUUUCCUGCUUCAACAGUGCUUGGACGGAACCCGGCGCUCGUUCCCCA'

for i in range(0, len(seq) - 16):

    test = seq[i:i + 16]
    if test[5:10] == 'CAGUG':
        strand1 = test[0:5]
        strand2 = test[11:16]
        if findstem(strand1, strand2):
            pos = i + 1
            print 'match at position', pos, ':'
            print test
            print '<----CAGUGN---->'