0

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!

Davidmh
  • 3,797
  • 18
  • 35
Adem
  • 5
  • 4
  • 1
    You should use `in` instead of `==`... – Willem Van Onsem Mar 13 '17 at 12:59
  • 1
    I guess you have to write `Codon in (...): ` instead of `==` – Dmitry Mar 13 '17 at 13:00
  • Also, `Codon = print(input(str("Please enter your codon: ")))` should just be `Codon = input("Please enter your codon: ")` – roganjosh Mar 13 '17 at 13:01
  • Please don't edit in extra, unrelated questions at the end once it has already been answered. You just need `Codon = input("Please enter your codon: ").upper()` but in future, research that point separately and if you can't find the answer, raise as another question. – roganjosh Mar 13 '17 at 13:17
  • Possible duplicate of [How do I test one variable against multiple values?](http://stackoverflow.com/questions/15112125/how-do-i-test-one-variable-against-multiple-values) – tripleee Mar 14 '17 at 12:36
  • Use a dictionary. You save each Codon as a key with it's corresponding Protein name. Then when the user inputs the codon you just pick the value from the dictionary. It's way cleaner than using conditionals with `and` and `or`. –  Mar 14 '17 at 12:41

1 Answers1

1

If you write:

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

Python will check if the Codon (a string) 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 in ("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: ")).strip()
#                                               ^ strip the new line

Nevertheless you better use a dictionary for that.

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
  • It was staring me right in the face, but I couldn't figure it out, thanks alot of the help! – Adem Mar 13 '17 at 13:09