首页 > 解决方案 > 如何识别有效的 DNA 序列?

问题描述

我刚刚开始学习如何在 python 中编码,并将其应用于生物信息学领域。不过,我在下一个程序时遇到了麻烦:

到目前为止,这或多或少是我所做的......它适用于具有 3 个或更多字符的序列,但是如果您在“不对,请再次输入序列:”之后写一个字母(无论哪个),它就会明白当它不是时,它是一个有效的序列。

def Start():

dna=input("Enter a sequence:  ")

for i in range(len(dna)):
    if dna[i] not in "actgn":
        dna=input("Not right, enter a sequence again:  ")
    else:
       break
print("here the program will continue")

标签: pythonpython-3.xstringloopsdna-sequence

解决方案


尝试这个:

dna=input("Enter a sequence:  ")
sequenceCorrect = False
while not sequenceCorrect:
    sequenceCorrect = True
    for i in range(len(dna)):
        if dna[i] not in "actgn":
            sequenceCorrect = False
    if not sequenceCorrect:
        dna=input("Incorrect Sequence Please Try Again:  ")
print("here the program will continue")


推荐阅读