[英]Can anyone help me figure out what's wrong with this code? Same RNA sequence matching program
[英]Can anyone help me find out what's wrong? Index error in my code
我正在用Python寫一個非常粗糙的Caesar Cipher,它可以很好地處理簡單的消息,但是當我輸入完整的字母時,我在第16行出現了錯誤,說有一個索引錯誤:字符串索引超出范圍。 誰能幫我找出問題所在? 這是我的代碼:
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.