Python 破环

Python 破环,python,django,Python,Django,我目前正在开发我的第一个网站。dna到蛋白质的翻译。当你输入密码子(由三个字母组成)tga、tag或taa时,情况就是这样。forloop应该停止。 基本上,我想停止forloop 代码如下: class TranslatorView(View): template_name = 'main/translated.html' def translate_amino(self, codon): return self.amino_mapper.get(c

我目前正在开发我的第一个网站。dna到蛋白质的翻译。当你输入密码子(由三个字母组成)tga、tag或taa时,情况就是这样。forloop应该停止。 基本上,我想停止forloop 代码如下:

class TranslatorView(View):
    template_name = 'main/translated.html'

    
    def translate_amino(self, codon):
        return self.amino_mapper.get(codon, "")


   

    def build_protein(self, phrase): #Here's the main problem
        protein = []
        i = 0
        while i < len(phrase):
            codon = phrase[i: i + 3]
            amino = self.translate_amino(codon)
            if amino:
                protein.append(amino)
            elif amino == "tag","tga","taa":
                break amino
                
            else:
                print(f"The codon {codon} is not in self.amino_mapper")
            i += 3
        return protein

class translator视图(视图):
模板名称='main/translated.html'
def翻译_氨基(自身,密码子):
返回self.aminou映射器.get(密码子“”)
def build_蛋白质(自我,短语):#这是主要问题
蛋白质=[]
i=0
而我
但是,我遇到了一些错误。有人知道如何解决这些问题吗

顺便说一句,主要问题是def build_蛋白质,在我试图破坏代码的情况下,它会引发语法错误

if amino:
    protein.append(amino)
elif amino == "tag","tga","taa":
If/else语句从上到下执行,在您的例子中,
elif
永远不会执行,因为即使
amino==“tag”
语句也会执行。 另外,
break
不是有效的语法,您应该这样编写elif:

elif amino in ("tag","tga","taa"):

break语句不返回任何可以设置的值 一个变量,然后检查循环中的值

def build_protein(self, phrase): #Here's the main problem
    protein = []
    i = 0
    while i < len(phrase):
        codon = phrase[i: i + 3]
        amino = self.translate_amino(codon)
        if amino:
            protein.append(amino)
        elif amino == "tag","tga","taa":
            new_amino=amino
            break
            
        else:
            print(f"The codon {codon} is not in self.amino_mapper")
        i += 3
    if new_amino:
       # do whatever
    return protein
def build_protein(self,短语):#这是主要问题
蛋白质=[]
i=0
而我
您能解释一下为什么用HTML和CSS标记这个吗?它们看起来根本不相关,除非我遗漏了什么什么错误?你能把它们也贴出来吗?你认为氨基==“tag”,“tga”,“taa”是什么意思?在尝试这样的项目之前,你真的应该确保你的基础更加坚实。在可以行走之前,您正在跑步。停止循环包含在任何有关循环的教程中。堆栈溢出不是为了替换现有的教程和文档。请提供预期的价格。显示中间结果与预期结果的偏差。我们应该能够将单个代码块粘贴到文件中,运行它,并重现您的问题。这也让我们可以在您的上下文中测试任何建议。张贴170行代码过多;要求我们教你一个基本的语言特征是离题的。