Home > Back-end >  After complement function can't print a string, and no error message is shown
After complement function can't print a string, and no error message is shown

Time:09-27

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

CodePudding user response:

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}")

CodePudding user response:

Maybe the issue is the fact that you're trying to print the value outside the function, but the variable was defined inside of it, in a smaller scope

CodePudding user response:

You are defining a function complement(), but you have not used this function. Try assigning the result of your function to a new variable, something like that:

dna_compl = complement(region)
print(dna_compl)
  • Related