[英]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.