函数输出什么都不显示,Python

时间:2017-12-06 05:25:27

标签: python function bioinformatics

我正在尝试在Python 3中创建一个程序,将DNA密码子转换为氨基酸,但是,在输入代码后,我没有得到任何错误消息,但是在运行代码和类型后该函数没有显示任何内容在DNA代码中。例如:ATTGTTTCT,应该显示ILE VAL SER,我没有得到ILE VAL SER。任何帮助将不胜感激。

DNA_sequence = input("Enter your DNA sequence below: \n")
DNA = DNA_sequence.upper()
DNA_to_codons = ([DNA[start:start + 3]] for start in range(0, len(DNA), 3))

print('The amino acid chain of your DNA sequence is as follows: \n')
for i in DNA_to_codons:
    if(i=="ATG"): print("MET", end = ' ')
    if(i=="TGA" or i=="TAA" or i=="TAG"): print("END", end = ' ')
    if(i=="TTT" or i=="TTC"): print("PHE", end = ' ')
    if(i=="TTA" or i=="TTG" or i=="CTT" or i=="CTC" or i=="CTA" or i=="CTG"): print("LEU", end = ' ')
    if(i=="ATT" or i=="ATC" or i=="ATA"): print("ILE", end = ' ')
    if(i=="GTT" or i=="GTC" or i =="GTA" or i=="GTG"): print("VAL", end = ' ')
    if(i=="TCT" or i=="TCC" or i=="TCA" or i=="TCG"): print("SER", end = ' ')
    if(i=="CCT" or i=="CCC" or i=="CCA" or i=="CCG"): print("PRO", end = ' ')
    if(i=="ACT" or i=="ACC" or i=="ACA" or i=="ACG"): print("THR", end = ' ')
    if(i=="GCT" or i=="GCC" or i=="GCA" or i=="GCG"): print("ALA", end = ' ')
    if(i=="TAT" or i=="TAC"): print("TYR", end = ' ')
    if(i=="CAT" or i=="CAC"): print("HIS", end = ' ')
    if(i=="CAA" or i=="CAG"): print("GLN", end = ' ')
    if(i=="AAT" or i=="AAC"): print("ASN", end = ' ')
    if(i=="AAA" or i=="AAG"): print("LYS", end = ' ')
    if(i=="GAT" or i =="GAC"): print("ASP", end = ' ')

1 个答案:

答案 0 :(得分:2)

在第三行代码中,更改

DNA_to_codons = ([DNA[start:start + 3]] for start in range(0, len(DNA), 3))

DNA_to_codons = (DNA[start:start + 3] for start in range(0, len(DNA), 3))

DNA_to_codons中的每个元素都是作为列表而不是字符串生成,使DNA_to_codons生成器包含原始代码中的列表,因此比较不能作为列表(即{ {1}})被比作一个字符串(即["ATT"])。