Skip to content
Advertisement

After complement function can’t print a string, and no error message is shown

rookie here. Can anyone tell me what is wrong with this? I cant seem to print my “primer” string, I am sure that the “region” variable is not empty for I tested it out already.

enter image description here

Advertisement

Answer

In the future, please post the text of your program, not an image of the program.

I modified your program to do what I think your intent was.

The main thing you needed to do was call complement(region) and assign the return value to a variable.

dna = "ATCGATCGATCGTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAG"
print(f"#1 'dna' len={len(dna)} {dna}")

start = "3"
end = "30"
dna = dna[int(start):int(end)]
print(f"#2 'dna' len={len(dna)} {dna}")

region = dna[0:20]
print(f"#2 'region'  len={len(region)} {region}")


def complement(region):
    comp = {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'}
    primer = ''
    for i in region:
        primer = primer + comp[i]
    return primer

com = complement(region)

print(f"'complement' len={len(com)} {com}")
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement