简体   繁体   中英

Codons Translation

I have been trying to do this little project where I make a program which the user will input three ammio acids like "ATC" and in return the program will tell it, its protein, but what I have written seems to not do what I want it

Codon = print(input(str("Please enter your codon: ")))
if Codon == ("ATT", "ATC", "ATA"):
    print("Isoleucine")
elif Codon == ("CTT", "CTC", "CTA", "CTG", "TTA", "TTG"):
    print("Leucine")
elif Codon == ("GTT", "GTC", "GTA", "GTG"):
    print("Valine")
elif Codon == ("TTT", "TTC"):
    print("Phenylalanine")
elif Codon == "ATG":
    print("Methionine")
elif Codon == ("TGT", "TGC"):
    print("Cysteine")
elif Codon == ("GCT", "GCC", "GCA", "GCG"):
    print("Alanine")
elif Codon == ("GGT", "GGC", "GGA", "GGG"):
    print("CodonGlycine")
elif Codon == ("CCT", "CCC", "CCA", "CCG"):
    print("Proline")
elif Codon == ("ACT", "ACC", "ACA", "ACG"):
    print("Threonine")
elif Codon == ("TCT", "TCC", "TCA", "TCG", "AGT", "AGC"):
    print("Serine")
elif Codon == ("TAT", "TAC"):
    print("Tyrosine")
elif Codon == "TGG":
    print("Tryptophan")
elif Codon == ("CAA", "CAG"):
    print("Glutamine")
elif Codon == ("AAT", "AAC"):
    print("Asparagine")
elif Codon == ("CAT", "CAC"):
    print("Histidine")
elif Codon == ("GAA", "GAG"):
    print("Glutamic_Acid")
elif Codon == ("GAT", "GAC"):
    print("Aspartic_Acid")
elif Codon == ("AAA", "AAG"):
    print("Lysine")
elif Codon == ("CGT", "CGC", "CGA", "CGG", "AGA", "AGG"):
    print("Arginine")
elif Codon == ("TAA", "TAG", "TGA"):
    print("Stop_Codons")
else:print("Something Went Wrong")

This output:

Please enter your codon: TGA TGA Something Went Wrong

What I want it to output:

Stop_Codon

any suggestions/help would be really appreciated Also I need to make it so it can accept lowercase letters as well, at this stage if one was to enter a lower case codon, it would just not work as intended!

If you write:

if Codon == ("ATT", "ATC", "ATA"):

Python will check if the Codon (a str ing) is equal to the tuple containing these three elements. Now since the type is not equal, it will not match the test. What you need is in to check if the Codon (for instance "ATC" ) is in the tuple . So:

if Codon  ("ATT", "ATC", "ATA"):
#        ^ use in

Furthermore you write:

Codon = print(input(str("Please enter your codon: ")))
#       ^ print??

Now print prints the input, and returns None . So you should rewrite it to:

Codon = input(str("Please enter your codon: "))
#                                               

Nevertheless you better use a dict ionary for that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM