简体   繁体   English

谁能帮我找出问题所在? 我的代码中出现索引错误

[英]Can anyone help me find out what's wrong? Index error in my code

I am writing a very rough Caesar Cipher in Python and it works fine with simple messages, but when I enter the full alphabet in, I get a error on my 16th line, saying that there is an index error: string index out of range. 我正在用Python写一个非常粗糙的Caesar Cipher,它可以很好地处理简单的消息,但是当我输入完整的字母时,我在第16行出现了错误,说有一个索引错误:字符串索引超出范围。 Can anyone help me find out what's wrong? 谁能帮我找出问题所在? Here's my code: 这是我的代码:

    abc = "ABCDEFGHIJKLMNOPQRTUVWXYZ"
    m = str(input("Message: "))
    m = m + "~"
    m_t = m.index("~")
    o = int(input("Offset: "))
    e_m = "Encrypted Message: "
    for loop_counter in range(m_t):
        c = m[loop_counter]
        if c in abc:
            p = abc.index(c)
            p = p + o
            if 25 < p:
                p = p - 26
            elif 0 > p:
                p = p + 26
            n_c = abc[p]
            e_m = e_m + n_c
        else:
            e_m = e_m + c

    print(e_m)

您的“ abc”字符串长度为25,您错过了“ S”字母...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 谁能帮我弄清楚这段代码有什么问题吗? 相同的RNA序列匹配程序 - Can anyone help me figure out what's wrong with this code? Same RNA sequence matching program 谁能告诉我这里的代码有什么问题? - Can anyone tell me what's wrong with my code here? 谁能找出这段代码有什么问题? - Can anyone find out what's wrong in this code? 运行时错误:谁能帮帮我? Python代码 - Runtime Error: Can anyone help me out? Python code 谁能帮助我找出这段代码中的解析错误? - Can anyone help me figure out the parsing error in this code? 谁能帮我在我的 python GUI 代码中找到错误? - Can anyone help me to find mistake in my python GUI code? 谁能告诉我我的功能出了什么问题? - Can anyone tell me what's wrong with my function? 谁能帮我理解为什么我有错误“列表索引超出范围”? - Can anyone help me to understand why i have the error “list index out of range”? 谁能帮我弄清楚如何将这个.txt文件导入我的代码? - Can anyone help me figure out how to import this .txt file into my code? 索引错误:列表索引超出范围。 谁能帮我解决这个 Python 代码? 包括 numpy 和 pandas 的概念 - IndexError: list index out of range. Can anyone help me out with this Python code ? Includes concepts of numpy and pandas
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM