Elifs条件在我的计划中不起作用

发布于 2025-02-13 21:56:32 字数 2081 浏览 2 评论 0原文

这是我的代码,需要许多密码子。密码子是一组三个核苷酸,每个核苷酸都编码为氨基酸
codon_sequence = []

print(“您想要的密码子no。输入”)

n = int(input())

for range(n)中的i:

codon=str(input())

codon_sequence.append(codon)

print(codon_sequence)

for range(n)中的i:

if(codon_sequence[i]=="UUU" or "UUC" or "TTT" or "TTC"):

    print("Phe_")

elif(codon_sequence[i]=="UUA" or "UUG" or "CUU" or "CUC" or "CUG" or "CUA" or "TTA" or "TTG" or "CTT" or "CTC" or "CTG" or "CTA"):

    print("Leu_")

elif(codon_sequence[i]=="UCU" or "UCC" or "UCG" or "UCA" or "AGU" or "AGC" or "TCT" or "TCC" or "TCG" or "TCA" or "AGT" or "AGC"):

    print("Ser_")

elif(codon_sequence[i]=="UAU" or "UAC" or "TAT" or "TAC"):

    print("Tyr_")

elif(codon_sequence[i]=="UGU" or "UGC" or "TGT" or "TGC"):

    print("Cys_")

elif(codon_sequence[i]=="UGG" or "TGG"):

    print("Trp_")

elif(codon_sequence[i]=="CCU" or "CCC" or "CCA" or "CCG" or "CCT"):

    print("Pro_")

elif(codon_sequence[i]=="CGU" or "CGC" or "CGA" or "CGG" or "AGA" or "AGG" or "CGT"):

    print("Arg_")

elif(codon_sequence[i]=="CAU" or "CAC" or "CAT"):

    print("His_")

elif(codon_sequence[i]=="CAA" or "CAG"):

    print("Gln_")

elif(codon_sequence[i]=="AUU" or "AUC" or "AUA" or "ATT" or "ATC" or "ATA"):

    print("Ile_")

elif(codon_sequence[i]=="AUG"):

    print("Met_")

elif(codon_sequence[i]=="ACU" or "ACC" or "ACA" or "ACG" or "ACT"):

    print("Thr_")

elif(codon_sequence[i]=="GUU" or "GUC" or "GUA" or "GUG" or "GTT" or "GTC" or "GTA" or "GTG"):

    print("Val_")

elif(codon_sequence[i]=="GCU" or "GCC" or "GCA" or "GCG" or "GCT"):

    print("Ala_")

elif(codon_sequence[i]=="GGU" or "GGC" or "GGA" or "GGG" or "GGT"):

    print("Gly_")

elif(codon_sequence[i]=="GAU" or "GAC" or "GAT"):

    print("Asp_")

elif(codon_sequence[i]=="GAA" or "GAG"):

    print("Glu_")

elif(codon_sequence[i]=="AAU" or "AAC" or "AAT"):

    print("Asn_")

elif(codon_sequence[i]=="AAA" or "AAG"):

    print("Lys_")

else:

    print("Stop_")

但是,这是给我的结果仅是“ phe_”,而忽略了所有其他条件

This is my code that takes a number of codons. Codons are a group of three nucleotides, each coding for an Amino Acid
codon_sequence=[]

print("Enter no. of codons you want")

n=int(input())

for i in range(n):

codon=str(input())

codon_sequence.append(codon)

print(codon_sequence)

for i in range(n):

if(codon_sequence[i]=="UUU" or "UUC" or "TTT" or "TTC"):

    print("Phe_")

elif(codon_sequence[i]=="UUA" or "UUG" or "CUU" or "CUC" or "CUG" or "CUA" or "TTA" or "TTG" or "CTT" or "CTC" or "CTG" or "CTA"):

    print("Leu_")

elif(codon_sequence[i]=="UCU" or "UCC" or "UCG" or "UCA" or "AGU" or "AGC" or "TCT" or "TCC" or "TCG" or "TCA" or "AGT" or "AGC"):

    print("Ser_")

elif(codon_sequence[i]=="UAU" or "UAC" or "TAT" or "TAC"):

    print("Tyr_")

elif(codon_sequence[i]=="UGU" or "UGC" or "TGT" or "TGC"):

    print("Cys_")

elif(codon_sequence[i]=="UGG" or "TGG"):

    print("Trp_")

elif(codon_sequence[i]=="CCU" or "CCC" or "CCA" or "CCG" or "CCT"):

    print("Pro_")

elif(codon_sequence[i]=="CGU" or "CGC" or "CGA" or "CGG" or "AGA" or "AGG" or "CGT"):

    print("Arg_")

elif(codon_sequence[i]=="CAU" or "CAC" or "CAT"):

    print("His_")

elif(codon_sequence[i]=="CAA" or "CAG"):

    print("Gln_")

elif(codon_sequence[i]=="AUU" or "AUC" or "AUA" or "ATT" or "ATC" or "ATA"):

    print("Ile_")

elif(codon_sequence[i]=="AUG"):

    print("Met_")

elif(codon_sequence[i]=="ACU" or "ACC" or "ACA" or "ACG" or "ACT"):

    print("Thr_")

elif(codon_sequence[i]=="GUU" or "GUC" or "GUA" or "GUG" or "GTT" or "GTC" or "GTA" or "GTG"):

    print("Val_")

elif(codon_sequence[i]=="GCU" or "GCC" or "GCA" or "GCG" or "GCT"):

    print("Ala_")

elif(codon_sequence[i]=="GGU" or "GGC" or "GGA" or "GGG" or "GGT"):

    print("Gly_")

elif(codon_sequence[i]=="GAU" or "GAC" or "GAT"):

    print("Asp_")

elif(codon_sequence[i]=="GAA" or "GAG"):

    print("Glu_")

elif(codon_sequence[i]=="AAU" or "AAC" or "AAT"):

    print("Asn_")

elif(codon_sequence[i]=="AAA" or "AAG"):

    print("Lys_")

else:

    print("Stop_")

This is however, giving me only 'Phe_' as result, and ignores all other conditions

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

弱骨蛰伏 2025-02-20 21:56:34

这将是Switch语句的绝佳候选人,但是正如先前的答案所述,您不能像您一样在每个字符串之间放置“或”。

This would be a great candidate for a switch statement, but as the previous answer mentioned you can't put an "or" between each string like you're doing.

落花随流水 2025-02-20 21:56:32

您的代码没有击中elif阻止

您的 和elif块的原因。

它应该检查codon_sequence [i]等于兴趣的字符串。

if(codon_sequence[i]=="UUU" or codon_sequence[i]=="UUC" or codon_sequence[i]=="TTT" or codon_sequence[i]=="TTC"):

取而代
如果条件始终为 true 。
,这将导致第一个
因此,您永远不会击中elif块。

如果语句是:编写的更好方法是:

if codon_sequence[i] in ["UUU", "UUC", "TTT", "TTC"]:
    print("Phe_")

Reason why your code is not hitting the elif blocks

Your if and elif blocks should look like this.
It should check if codon_sequence[i] is equal to a string of interest.

if(codon_sequence[i]=="UUU" or codon_sequence[i]=="UUC" or codon_sequence[i]=="TTT" or codon_sequence[i]=="TTC"):

Instead you have an or condition against just plain strings like UUC.
This will result in the first if condition always being True.
Thereby you will never hit the elif block.

Also a better way of writing the if statement would be:

if codon_sequence[i] in ["UUU", "UUC", "TTT", "TTC"]:
    print("Phe_")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文