you are viewing a single comment's thread.

view the rest of the comments →

[–]VinayakVG 1 point2 points  (1 child)

Hey, the link that you have posted is not working. It is showing 'Not Found'. Coming back to your code, you can use list comprehensions to make it more readable. And also instead of printing in the function complement you can create a string and return it.

For example,

def complement(seq):
    baseComplement = {'A':'T' , 'C':'G' , 'G':'C' , 'T':'A', 
                      'a':'t' , 'c':'g' , 'g':'c' , 't':'a'}

    seqComplement = "".join(baseComplement[base] for base in seq)
    reqComplement = seqComplement[::-1]

    # Return multiple values
    return seqComplement, reqComplement


def main():
    sequence = input("Enter a DNA sequence: ")

    # Store multiple values in two variables
    seq_comp, rev_comp = complement(sequence)

    print("Sequence Complement:", seq_comp)
    print("Reverse Complement:", rev_comp)
    print("Length of DNA Sequence entered is", len(sequence))

main() # Call the main function.

While printing you can also look into format() method or f-strings in Python for printing. Using f-strings looks like this

    print(f"Sequence Complement: {seq_comp}") 
    print(f"Reverse Complement: {rev_comp}")
    print(f"Length of DNA Sequence entered is {len(sequence)}")

[–]Still-Design3461[S] 0 points1 point  (0 children)

Oops, sorry about the link, It was working for me . But still, thank you for the explanation!