<p>我是编程新手,我正在尝试编写一个关于DNA的代码,用户输入一个特定的DNA序列。然后程序必须将输入的DNA翻译成特定的氨基酸。你知道吗</p>
<p>我尝试将用户输入的每个DNA字符串转换成一个列表,然后使用“in”函数查看用户输入的哪个DNA与特定的氨基酸相对应。我的代码如下:</p>
<pre><code>dna = input("please enter the DNA sequence in CAPS: ")
# a variable called codons to convert the entered DNA sequence into a list of 3 characters per element
codons = [dna[start:start+3] for start in range (0,len(dna),3)]
# we now create an if structure which matches each codon to its appropriate amino acid
if "ATA" or "ATC" or "ATT" in codons:
print("Isoleucine")
if "CTT" or "CTC" or "CTA" or "CTG" or "TTA" or "TTG" in codons:
print("Leucine")
if "GTT" or "GTC" or "GTA" or "GTG" in codons:
print("Valine")
if "TTT" or "TTC" in codons:
print("Phenylalanine")
if "ATG" in codons:
print("Methionine")
</code></pre>
<p>问题是当我运行代码时,它打印的是大多数密码子类型而不是特定的氨基酸,例如,如果用户输入“ATA”,它打印的是异亮氨酸、亮氨酸、缬氨酸和苯丙氨酸,而不是只打印异亮氨酸。你知道吗</p>