我一直在尝试做这个小项目,在那里我制作一个程序,用户将输入三个氨基酸,如#34; ATC"作为回报,程序会告诉它,它的蛋白质,但我写的东西似乎没有做我想要的东西
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")
此输出:
Please enter your codon: TGA TGA Something Went Wrong
我想要输出的内容:
Stop_Codon
任何建议/帮助都会非常感激 此外,我需要这样做它也可以接受小写字母,在这个阶段,如果要输入一个小写密码,它就不会按预期工作!
答案 0 :(得分:1)
如果你写:
if Codon == ("ATT", "ATC", "ATA"):
Python将检查Codon
(a str
ing)是否等于到包含这三个元素的元组。现在由于类型不相等,它将与测试不匹配。您需要in
来检查Codon
(例如"ATC"
)在元组中是否 。所以:
if Codon in ("ATT", "ATC", "ATA"):
# ^ use in
此外你写道:
Codon = print(input(str("Please enter your codon: ")))
# ^ print??
现在print
打印输入,返回None
。所以你应该把它重写为:
Codon = input(str("Please enter your codon: ")).strip()
# ^ strip the new line
然而,你最好使用dict
离子。